程式應該在第一個回圈中搜索影像并將其添加到串列中,在第二個回圈中他應該搜索直到找到不在串列中的影像。PyCharm 給了我while search = True: and if pic == used預期的錯誤。
used = []
search = True
#First Loop
while True:
pic = driver.find_element(By.CSS_SELECTOR,value=".image-post img")
time.sleep(2)
pic_url = pic.get_attribute("src")
pic_title = pic.get_attribute("alt")
used.append(pic)
time.sleep(200)
#Second loop
while search = True:
pic = driver.find_element(By.CSS_SELECTOR, value=".image-post img")
if pic == used
search = True
else:
search = False
used.append(pic)
...
uj5u.com熱心網友回復:
嘗試這個
used = []
#First Loop
while True:
search = True #moved search = True here so that the nested loop will run each iteration of the main loop as it will be set back to True
pic = driver.find_element(By.CSS_SELECTOR,value=".image-post img")
time.sleep(2)
pic_url = pic.get_attribute("src") #you’re not doing anything with this from the looks of it
pic_title = pic.get_attribute("alt") #same with this
used.append(pic)
time.sleep(200)
#Second loop
while search:
pic = driver.find_element(By.CSS_SELECTOR, value=".image-post img")
if pic != used:#may want to change “used” to “used[-1]” here as used is a list while it appears pic is not, so the -1 will get the last value in used
search = False
used.append(pic)
您還可以將搜索替換為 True 并將“search = False”更改為“break”
uj5u.com熱心網友回復:
我認為您使用了錯誤的運算子型別。我的意思是你應該使用==而不是=。 檢查并通知我。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/482190.html
上一篇:獲取嵌套陣列JS中物件的所有父項
