你看下divs有没有值,打印它的长度。
程序没有问题,运行可以得到数据结果。注意字符串的标点符号要用英文标点,也可以在get函数中添加headers。将下面代码复制到电脑上运行,试一下看。
import requests
from lxml import etree
url='https://www.zbj.com/search/f/?type=new&kw=sass'
resp=requests.get(url)
html=etree.HTML(resp.text)
divs=html.xpath('/html/body/div[6]/div/div/div[2]/div[5]/div/div')
print(divs)
for div in divs:
price=div.xpath("./div/div/a/div[2]/div[1]/span[1]/text()")
title = div.xpath("./div/div/a/div[2]/div[2]/p/text()")
print(title)
print(price)