[英]Selenium Webdriver doesnt find ALL elements on website
我一直在開發Instagram自動化程序,但是有一個問題:當我嘗試查找所有LIKE按鈕並打印它們時
它只喜歡前4張圖片,但還有更多,我不知道為什么找不到它們
使用Selenium,Python,Selenium Webdriver,時間,鍵(來自selenium)代碼:
hearts = browser.find_elements_by_xpath("//*[contains(@class, '_eszkz
_l9yih')]")
for i, heart in enumerate(hearts):
print('{}/{}'.format(i, len(hearts)))
heart.click()
time.sleep(2)
這是Instagram加載頁面項目的唯一方式
Instagram一次只加載4張圖片
需要向下滾動頁面以加載更多內容
hearts = driver.find_elements_by_xpath("//*[contains(@class, '_eszkz _l9yih')]")
while True: #infinite loop
q = len(hearts)
last_item = hearts[q-1]
for i, heart in enumerate(hearts):
print('{}/{}'.format(i, len(hearts)))
#heart.click()
sleep(2)
last_item.location_once_scrolled_into_view
hearts = driver.find_elements_by_xpath("//*[contains(@class, '_eszkz _l9yih')]")
獲取最后一個項目列表,然后滾動到它並重新加載列表
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.