[问题] Xpath抓不到内容

楼主: garlic774 (蒜头)   2021-11-20 20:14:52
各位大大晚安,以Xpath抓,一直结果none,请问有可能是哪边出了问题呢?
[in]
!pip install selenium
from selenium import webdriver
import time
import pandas as pd
browser = webdriver.Chrome(executable_path='./chromedriver.exe')
browser.get("https://tw.mall.yahoo.com/store/%E5%B1%88%E8%87%A3%E6%B0%8FWatson
s:
time.sleep(5)
# 商品连结
# 如何找到rel Xpath ?
linkpath = '//ul[@class = "sc-eWvPqa cePswM"]/li/a'
product_links = browser.find_elements_by_xpath(linkpath)
product_link = product_links[0].get_attribute('href')
print('商品连结:',product_link)
[out]
IndexError Traceback (most recent call last)
<ipython-input-22-cb447ba73a6b> in <module>
11 linkpath = '//ul[@class = "sc-eWvPqa cePswM"]/li/a'
12 product_links = browser.find_elements_by_xpath(linkpath)
作者: sating00 (sating00)   2021-11-21 14:41:00
报错不是很清楚吗?out of range 就是你给的数超过list上限先检查 product_links 到底有没有东西吧
楼主: garlic774 (蒜头)   2021-11-21 19:09:00
谢谢S大 我再试试看
作者: TakiDog (多奇狗)   2021-11-21 19:29:00
用chrome debugger 搜寻看看吧尽可能不要用自动产生的xpath(判断太严格)手动写判断不难
楼主: garlic774 (蒜头)   2021-11-21 22:13:00
后来改成 //a去搜寻,再用if in: 也筛选出来了 感谢大大们

Links booklink

Contact Us: admin [ a t ] ucptt.com