繁体   English   中英

Python Selenium 在特定日期查找元素(标题)

[英]Python Selenium find element (title) in a specific date

我正在使用 Selenium 来取回在特定日期发布的一些文章

我试过了:

driver.get('https://www.globalcapital.com/Asia/Bonds/Corp')
while True:
    links=[link.get_attribute('href') for link in driver.find_elements_by_xpath("//div[contains(@title,'01 Feb 2021')/preceding::a[2]")]
    for link in links:
        # I want to return all href first to a csv
        # and then return to the title of the article

但是'不是一个有效的 XPath 表达式',我在这里有两个问题:

  1. 进行仅用于兄弟元素吗? 2.我怎样才能得到日期和 go 回到元素来精确href并获取文本?

提前致谢!

它无效,因为您忘记了右方括号。 尝试

"//div[contains(@title,'01 Feb 2021')]/preceding::a[2]"

不, preceding / following不仅用于兄弟姐妹。 preceding-sibling / following-sibling仅用于兄弟姐妹

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM