爬取猪八戒网站_wx634e10232b539的技术博客_51CTO博客
source link: https://blog.51cto.com/u_15834166/5852667
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
爬取猪八戒网站
精选 原创爬取猪八戒网站
1.网站分析
首先在搜索框中输入saas
我们主要获取价格、标题、评分、销量、好评、企业名称,在使用Xpath的时侯,从网站上复制的Xpath和返回的Xpath存在差异,所以我们在获取的时候按class进行查找。
2.代码实现
import requests
from lxml import etree
url = 'https://shijiazhuang.zbj.com/search/service/?kw=saas&r=2'
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36'
}
resp = requests.get(url=url, headers=headers)
html = etree.HTML(resp.text)
datas = html.xpath('//*[@id="__layout"]/div/div[3]/div/div[3]/div[4]/div[1]/div')
info_list = []
for data in datas:
# 网页上的路径和实际路径不同
price = data.xpath('.//div[@class="price"]/span/text()')[0] # 价格
title = data.xpath('.//div[@class="name-pic-box"]/a/text()')[0] # 标题
score = data.xpath('.//div[@class="fraction"]/span[1]/text()')[0] # 评分
sale = data.xpath('.//div[@class="sales"]//span[@class="num"]/text()')[0] # 销量
good = data.xpath('.//div[@class="evaluate"]//span[@class="num"]/text()')[0] # 好评
com_name = data.xpath('.//div[@class="shop-info text-overflow-line"]/text()')[0] # 公司名
info = {
'价格': price,
'标题': title,
'评分': score,
'销量': sale,
'好评': good,
'公司名': com_name
}
info_list.append(info)
pd.DataFrame(info_list).to_csv('../data/猪八戒.csv')
3.结果查看
打开文件:
- 赞
- 收藏
- 评论
- 分享
- 举报
上一篇:Scrapy爬取豆瓣TOP250
Recommend
-
28
最近公司写爬虫 但是对于 前端渲染的网站(vue,react) 但是 chromedp selenium等又太重了 于是用puppeteer koa2 写了一个 通用服务 https://github.com/dollarkillerx/marionette
-
3
5分钟用Python爬取整个网站,你值得拥有 67回复 /3亮 172527 浏览 视频无法播放,浏览器版本过低,请升级浏览器或者使用其他浏览器
-
4
用python爬取某宝热卖网站商品信息(爬虫之路,永无止境!) 代码操作展示:
-
9
kubernetes FAQ 原创 cuiyingfeng 2022-04-25 10:18:58 博主文章...
-
2
Python 爬取 CSDN 博客信息 发表于: 2019-04-09
-
6
基于第一个项目爬虫爬取的数据,完成数据展示网站 基本要求 用户注册登录,非注册登录用户不可查看 用户注册、登录、查询数据入库 查询结果支持分页以及排序(
-
4
C语言笔记(三) 原创 小宋的博客 2022-05-25 00:30:33...
-
9
BGP配置实验 原创 阿杰无敌 2022-05-25 11:27:42...
-
1
C#的学习网站 精选 原创 名称:快速入门地址:http://chs.gotdotnet.com/quickstart/描述:本站点是微软.NET技术的...
-
3
“细雨下落花点碎,微风里水音飘流。” Python爬虫入门:爬取自己的博客文本 虽然更新频率有点低。。。但是我还是要纠正一下: 逃票的不是莱莎3是
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK