[英]How can I perform clicks on some links to get to the target page?
我已經用python用selenium編寫了一個腳本,以執行對某些鏈接的點擊以到達目標頁面。 但是,鏈接存儲在javascript加密的html元素中。 如何才能從這些元素中建立常規的“ href”鏈接,以便可以單擊該鏈接以到達目標頁面? 目前,我得到的數字是“ href”,非常類似於“ javascript:getDetail(19978)”。 這是我到目前為止寫的:
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get('https://www.aopa.org/learntofly/school/')
driver.find_element_by_id('searchTerm').send_keys('All')
time.sleep(5)
driver.find_element_by_id('btnSearch').click()
time.sleep(3)
for items in driver.find_elements_by_xpath('//td/a'):
print(items.get_attribute('href'))
driver.quit()
href鏈接應存儲在其中的元素:
<td><a href="javascript:getDetail(19978)">GOLD DUST FLYING SERVICE, INC.</a></td>
您可以執行以下腳本方法,
driver.execute_script("javascript:getDetail(19978)")
要么
driver.execute_script(items.get_attribute('href'))
或嘗試一下,
item.click();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.