我需要 src-0、src-1、src-2…src-59 附近的鏈接。我怎么能修復編碼?謝謝
!pip install selenium
from selenium import webdriver
import time
import pandas as pd
browser = webdriver.Chrome(executable_path='./chromedriver.exe')
browser.implicitly_wait(5)
browser.get("https://tw.mall.yahoo.com/store/屈臣氏Watsons:watsons")
# 商品連結
linkPath = "//ul[@class='gridList']/li/a"
product_links = browser.find_elements_by_xpath(linkPath)
print(product_links)
uj5u.com熱心網友回復:
在xpath您使用的是不突出的DOM任何元素。
嘗試如下,希望這些是您要提取的鏈接。
# Imports Required
from selenium import webdriver
from selenium.webdriver.common.by import By
driver.get("https://tw.mall.yahoo.com/store/屈臣氏Watsons:watsons")
links = driver.find_elements(By.XPATH,"//section[contains(@class,'MainListing__StoreBoothWrap')]/div/div/div/ul/li/a")
print(len(links))
for link in links:
print(link.get_attribute("href"))
60
https://tw.mall.yahoo.com/item/p0330231079018
https://tw.mall.yahoo.com/item/p0330221397264
https://tw.mall.yahoo.com/item/p0330201617111
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/363273.html
