我想使用Xpath单击目录列表,但是Xpath在此URL中完全不起作用 https://www.hindawi.com/journals/ecam/contents/
答案 0 :(得分:1)
使用CSS选择器代替XPath:
CSS选择器: a[href='/journals/ecam/2019/']
点击代码:
content = driver.find_element_by_css_selector("a[href='/journals/ecam/2019/']")
答案 1 :(得分:0)
我不知道为什么您在使用XPath时遇到问题...
此代码段对我来说效果很好:
from selenium import webdriver
driver = webdriver.Chrome(r'C:\path\to\chromedriver.exe')
driver.get('https://www.hindawi.com/journals/ecam/contents/')
driver.find_element_by_xpath('//*[@id="TableofContentsNav"]').click()
all_links = driver.find_elements_by_xpath('//*[@class="middle_content"]//*[@href]')
for i in all_links:
print(i.get_attribute('href'))
希望这对您有所帮助!