第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

通過xpath查找多個(gè)td標(biāo)簽

通過xpath查找多個(gè)td標(biāo)簽

元芳怎么了 2024-01-03 15:47:37
如果滿足兩個(gè)條件,我想從該網(wǎng)站https://www.asx.com.au/asx/statistics/prevBusDayAnns.do下載 PDF 文件。第一個(gè)條件是“ASX 代碼”必須與列表中的代碼之一匹配。第二個(gè)條件是“標(biāo)題”必須與“實(shí)質(zhì)性持有量變化”相匹配。我當(dāng)前的代碼僅在“ASX Code”=“SPL”時(shí)通過 xpath 查找。我想要實(shí)現(xiàn)的目標(biāo)的一個(gè)例子:data1 = ['SPL', 'WBC', 'AAA']WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//table//tr//td[text()={data1}]/following-sibling::td[3]/a"))).click()我的代碼: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")WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//table//tr//td[text()='SPL']/following-sibling::td[3]/a"))).click()WebDriverWait(driver,15).until(EC.number_of_windows_to_be(2))driver.switch_to.window(driver.window_handles[-1])WebDriverWait(driver,15).until(EC.element_to_be_clickable((By.XPATH,"//input[@value='Agree and proceed']"))).click()
查看完整描述

1 回答

?
慕容3067478

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")


查看完整回答
反對(duì) 回復(fù) 2024-01-03
  • 1 回答
  • 0 關(guān)注
  • 211 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)