我已經(jīng)用 Python 編寫了一個與 selenium 相關(guān)的腳本,以不斷單擊MORE按鈕以加載更多項目,直到?jīng)]有新項目可以從網(wǎng)頁加載為止。但是,我的以下腳本可以單擊MORE該頁面底部可用的按鈕一次。到目前為止,這是我的嘗試:from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as EClink = "https://angel.co/companies?company_types[]=Startup&company_types[]=Private+Company&company_types[]=Mobile+App&locations[]=1688-United+States"driver = webdriver.Chrome()wait = WebDriverWait(driver, 10)driver.get(link)while True: for elems in wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,".results .name a.startup-link"))): print(elems.get_attribute("href")) try: loadmore = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,"[class='more']"))) driver.execute_script("arguments[0].scrollIntoView();", loadmore) loadmore.click() except Exception:breakdriver.quit()我怎么能一直點擊那個MORE按鈕,直到?jīng)]有這樣的按鈕可以點擊和解析鏈接,因為我已經(jīng)嘗試過使用for loop.
添加回答
舉報
0/150
提交
取消