簡體   English   中英

無法從網頁中獲取表格中的所有pdf鏈接

[英]Can't grab all the pdf links within a table from a webpage

我已經寫在與硒結合的Python腳本來刮不同的pdf在點擊不同的數字生成的鏈接,如110015710110015670位於表內的網頁等。

網站連結

我的腳本可以單擊那些鏈接,顯示pdf文件,但只解析其中的5個。

我怎樣才能全部得到?

到目前為止,我已經嘗試過:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

link = "replace_with_above_link"

driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
driver.get(link)

[driver.execute_script("arguments[0].click();",item) for item in wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,"tr.Iec")))]
for elem in wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,".IecAttachments li a[href$='.pdf']"))):
    print(elem.get_attribute("href"))
driver.quit() 

當您單擊該元素時,它將執行XHR請求pdf鏈接,請在每次單擊后添加延遲。

for item in wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,"tr.Iec"))):
    driver.execute_script("arguments[0].click();",item)
    time.sleep(1)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM