from lxml import etree
import requests
# 拿到源代码
# 提取解析数据
url="https://nanchang.zbj.com/search/f/?kw=saas"
resp=requests.get(url)
# print(resp.text)
#解析
html=etree.HTML(resp.text)
#拿到每一个服务商的div
divs=html.xpath("/html/body/div[6]/div/div/div[2]/div[5]/div[1]/div")
for div in divs:
price=div.xpath("./div/div/a[2]/div[2]/div[1]/span[1]/text()")[0].strip("¥")
title=div.xpath("./div/div/a[2]/div[2]/div[2]/p/text()")[0].strip("/")
company='saas'.join(div.xpath("./div/div/a[1]/div[1]/p/text()"))[0]
location=div.xpath("./div/div/a[1]/div[1]/div/span/text()")[0]
print(title)
Python爬虫案例-猪八戒
最新推荐文章于 2024-08-15 19:56:03 发布