def items(self, task, response):
items = []
document = lxml.html.document_fromstring(html=response.text)
products = document.xpath("//div[@class='product']")
for product in products:
iid = int(product.xpath(".//@product-id")[0])
name = product.xpath(".//h2/text()")[0]
desc = product.xpath(".//p/text()")[0]
category = product.xpath(".//span/text()")[0]
price = float(product.xpath(".//em/text()")[0])
images = product.xpath(".//div//img/@src")
item = Product(
iid=iid,
url=response.url,
name=name,
category=category,
desc=desc,
price=price,
images=images,
)
items.append(item)
return items
评论列表
文章目录