[問題] Xpath抓不到內容
各位大大晚安,以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)
---> 13 product_link = product_links[0].get_attribute('href')
14 print('商品連結:',product_link)
IndexError: list index out of range
請問有可能是防爬的原因嗎? 還是哪邊有錯誤嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.25.201.214 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1637410494.A.50D.html
※ 編輯: garlic774 (114.136.86.16 臺灣), 11/21/2021 09:05:52
→
11/21 14:41,
3年前
, 1F
11/21 14:41, 1F
→
11/21 14:41,
3年前
, 2F
11/21 14:41, 2F
→
11/21 14:44,
3年前
, 3F
11/21 14:44, 3F
→
11/21 19:09,
3年前
, 4F
11/21 19:09, 4F
→
11/21 19:29,
3年前
, 5F
11/21 19:29, 5F
→
11/21 19:30,
3年前
, 6F
11/21 19:30, 6F
→
11/21 19:30,
3年前
, 7F
11/21 19:30, 7F
→
11/21 22:13,
3年前
, 8F
11/21 22:13, 8F
→
11/21 22:13,
3年前
, 9F
11/21 22:13, 9F
Python 近期熱門文章
PTT數位生活區 即時熱門文章