【发布时间】:2021-06-29 11:00:33
【问题描述】:
我想抓取产品标题、产品链接、产品价格,但是当我使用 xpath 时,它显示的是空列表。如何添加 xpath 和 for 循环以获取上述详细信息。这个我试过了
import requests
import lxml.html
html = requests.get("https://www.lazada.sg/catalog/?
q=Samsung+Mobile&_keyori=ss&from=input&spm=a2o42.home.search.go.654346b52P3y8Y")
doc = lxml.html.fromstring(html.content)
#print(doc)
new = doc.xpath('//div[@class ="index__box___1Ffv-"]')
print(len(new))
for node in new:
title = node.xpath('//*
[@id="root"]/div/div[2]/div[1]/div/div[1]/div[2]/div[1]/div/div/div[2]/div[2]/text()')
print(len(title))
print(title)
我需要获取上面提到的所有产品详细信息。我想要这个只使用 lxml 库。
【问题讨论】: