簡體   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