2016-09-09 31 views
-6

如何在腳本中循環下面的邏輯,直到全部刪除,然後繼續下一個文本。如何創建一個循環來檢查「刪除」是否存在多個「刪除」

if Text("Remove").exists(): 
click("Remove") 

闡釋:

==============

WEBPAGE 1個 CONTENTS:

- A(刪除) - 乙(REMOVE) - C(REMOVE)

[「Remov E」是一個可點擊的鏈接,消除A,B,C]

==============

現在我的腳本的一部分:

如果文本(「刪除」)存在(): 點擊(‘刪除’) 點擊(‘OK’)

===============

結果:

WEBPAGE 1 CONTENTS:

-

- B(刪除) - C(刪除)

================

以上A被腳本刪除。 我的問題是我怎麼能環路,所以結果是:

===============

結果:

WEBPAGE 1項 內容:

-

-

-

================

因此,對於包含「刪除」的網頁上的每個文本, 它會執行腳本,直到沒有「刪除」了。

+1

字符串列表,迭代列表?需要更多細節才能完全回答。 – SiHa

+0

嗨,沒有對應的字符串。編輯帖子。 – Gorilla

+1

你是什麼意思? '「刪除」是一個字符串。你需要提供更多關於你想要做什麼的信息。現在,你的問題不清楚,可能會被關閉。 – SiHa

回答

0

字符串有一個替代,你可以直接使用與''

page = 'Lorem remove ipsum elit remove id justo eu, finibus remove' 
page2 = 'Class aptent taciti sociosqu ad litora remove remove remove' 

pageList = [page, page2] 

for page in pageList: 
    while 'remove' in page: 
     page = page.replace('remove', '') 
    print page 

#Out: Lorem ipsum elit id justo eu, finibus 
#Out: Class aptent taciti sociosqu ad litora 

替換的單詞如果是特定的HTML內容替換方法。

page.replace('<a id="Remove">Remove</a>', '') 

讓我知道是否有幫助。

+0

即將進入研究階段,迴應即將到來。 – Gorilla

+0

上面解釋了更多! – Gorilla

+0

嘗試將'if'改爲'while' – garg10may

0

因爲你的頭腦是圍繞一個.remove()軌道:

a = 'This is just a Test' 
a_list = [] 

for i in range(0, len(a) - 1): 
    a_list.append(a[i]) 

while 't' in a_list: a_list.remove('t') # This Removes all lower case "t"s in a_list 

a = '' 

# Then you can change it into a string again : 
for n in range(0, len(a_list) - 1): 
    a += a_list[n] 

print(a) # This is the original 'a' only without lower case "t"s 

但這做(它有點嘲笑)我推薦一個好辦法:

.replace(,)

這已經解釋了

+0

上面解釋了更多! – Gorilla

相關問題