#拿到页面源代码
#提取和解析数据
import requests
from lxml import etree
url = "https://beijing.zbj.com/search/f/?kw=saas"
resp = requests.get(url)
resp.close()
# 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 = "saas".join(div.xpath("./div/div/a[2]/div[2]/div[2]/p/text()"))
com_name = div.xpath("./div/div/a[1]/div[1]/p/text()")
location = div.xpath("./div/div/a[1]/div[1]/div/span/text()")[0]
print(title)
python爬虫之xpath模块
最新推荐文章于 2024-04-07 08:00:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)