[英]Python selenium xpath using contains and not contains
我嘗試獲取標題包含某些單詞同時不包含某些單詞的鏈接,我使用以下代碼,但它說不是有效的 XPath 表達式。
請在這里找到我的代碼:
任何幫助將不勝感激!
driver.get("http://www.csisc.cn/zbscbzw/isinbm/index_list_code.shtml")
while True:
links = [link.get_attribute('href') for link in driver.find_elements_by_xpath("//a[(contains(@title,'公司債券')and not(contains(@title,'短期'))]")]
for link in links:
driver.get(link)
#dosth
and
之前應該有空格。 您的 XPath 中還有額外的前導括號。 嘗試:
"//a[contains(@title,'公司債券') and not(contains(@title,'短期'))]"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.