1 回答

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊
在所在位置的網(wǎng)頁上找不到包含 ASX 代碼的數(shù)據(jù)集。但是,data1 = ['SPL', 'WBC', 'AAA']這里是如何按順序下載多個(gè) ASX 代碼的示例。
數(shù)據(jù)集:data1 = ['SW1', 'AME', 'BGA','PPT','AMP']
將 的值存儲(chǔ)href在列表中,然后迭代該列表并單擊“同意”按鈕下載 pdf。
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
import time
chromeOptions=webdriver.ChromeOptions()
prefs = {"plugins.always_open_pdf_externally": True}
chromeOptions.add_experimental_option("prefs",prefs)
driver=webdriver.Chrome(executable_path=r"C:\Users\Harrison Pollock\Downloads\Python\chromedriver_win32\chromedriver.exe",chrome_options=chromeOptions)
driver.get("https://www.asx.com.au/asx/statistics/prevBusDayAnns.do")
data1 = ['SW1', 'AME', 'BGA','PPT','AMP']
pdfUrls=[]
for d in data1:
? ? try:
? ? ? ?pdfurl=driver.find_element_by_xpath("http://table//tr//td[text()='{}']/following-sibling::td[3]/a[contains(.,'{}')]".format(d,"Change in substantial holding")).get_attribute("href")
? ? ? ?pdfUrls.append(pdfurl)
? ? except:
? ? ? ? print("No ASX code found with Headline Change in substantial holding : " + d)
for pdfurl in pdfUrls:
? ? driver.get(pdfurl)
? ? WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH, "http://input[@value='Agree and proceed']"))).click()
? ? time.sleep(10)? # pause to check download
? ? print("Downloaded pdf file")
- 1 回答
- 0 關(guān)注
- 211 瀏覽
添加回答
舉報(bào)