![](/img/trans.png)
[英]Trouble getting the second link when the first link contains certain keyword right next to it
[英]xpath to href that contains certain keyword in link itself
我需要的是找到頁面上鏈接本身內有一些關鍵字的所有鏈接。 所以,根據一些堆棧主題,我構建我的xpath如下:
response.xpath('//a[contains(@href,'/Best-Sellers-Health-Personal-Care')]')
應返回類似=“ https://www.amazon.com/Best-Sellers-Health-Personal-Care-Tongue ......”的鏈接
但我總是得到無效的語法錯誤。 我錯了什么? 所以我現在所做的只是在迭代列表時添加if包含檢查。 但希望有更優雅和快速的解決方案。
這是因為引號使用不一致。
只需更換
'//a[contains(@href,'/Best-Sellers-Health-Personal-Care')]'
同
'//a[contains(@href,"/Best-Sellers-Health-Personal-Care")]'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.