当前位置:网站首页>爬虫框架-crawler
爬虫框架-crawler
2022-07-25 17:07:00 【wangmcn】
crawler
目录
- 1、简介
- 2、安装部署
- 3、框架说明
- 4、使用框架
1、简介
crawler采用requests+lxml的方式进行爬虫,爬取内容和url采用XPath方式一致(关于XPath可参考XPath参考手册章节)。
GitHub网址:https://github.com/shuizhubocai/crawler
requests是Python的一个优秀第三方库,适合于人类使用的HTTP库,封装了许多繁琐的HTTP功能,极大地简化了HTTP请求所需要的代码量。
lxml是Python的一个解析库,支持HTML和XML的解析,支持XPath解析方式,而且解析效率非常高。
2、安装部署
在Windows环境(64位)下Python版本为3.6.5。
1、打开官方网址进行下载,下载完成为crawler-master.zip文件。
2、解压文件到指定目录(例如D:\crawler)。
3、安装目录下,命令行运行pip install -r requrements.txt安装框架所依赖的库文件。
requrements.txt文件内容:
certifi==2018.4.16
chardet==3.0.4
idna==2.7
requests==2.19.1
urllib3==1.23
4、安装lxml,版本号为4.2.5。
下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml
下载指定版本,cp36代表Python 3.6的版本,win_amd64代表64位的系统,所以需要选择正确,否则安装过程会报错平台不匹配。
下载完成后开始安装lxml,在命令行中进入安装文件所在路径输入命令即可。
pip install lxml-4.2.5-cp36-cp36m-win_amd64.whl
3、框架说明
1、crawler.py文件:
Urls类:地址管理器
Download类:页面下载器
Parser类:页面解析器
Output类:导出数据到HTML
Scheduler类:爬虫调度器
2、modules\useragent目录下的chrome.py、firefox.py等为浏览器代理。
3、data.html将爬取的数据导入到此文件里。
4、使用框架
需求:访问51testing论坛,获取指定页数(1-10)的帖子标题和URL地址。
如图所示:要获取的帖子标题。
如图所示:获取1-10页。
1、修改脚本(crawler.py文件)。
(1)修改Parser类,getDatas方法的html.xpath值。
//tbody[contains(@id,'normalthread')]/tr/th/a[3]
如图所示:使用Firefox+FirePath进行调试定位。
(2)修改Parser类,getUrls方法的html.xpath值。
//span[@id='fd_page_bottom']/div//a[not(@class)]//@href
如图所示:使用Firefox+FirePath进行调试定位。
(3)实例化
添加访问地址:http://bbs.51testing.com/forum-279-1.html
2、执行脚本(crawler.py文件)。
安装目录下,命令行运行python crawler.py
3、查看爬取结果。
脚本执行完成后,在安装目录下会自动生成data.html文件。
打开data.html文件,显示爬取后的数据,点击标题会弹出新窗口跳转到指定地址。
边栏推荐
- Exception handling mechanism topic 1
- Jenkins' file parameters can be used to upload files
- Rosen's QT journey 100 QML four standard dialog boxes (color, font, file, promotion)
- 2022年最新北京建筑施工焊工(建筑特种作业)模拟题库及答案解析
- EasyUI drop-down box, add and put on and off shelves of products
- Headless mode of new selenium4.3 in egde browser
- Rainbow plug-in extension: monitor MySQL based on MySQL exporter
- [mathematical modeling and drawing series tutorial] II. Drawing and optimization of line chart
- In the eyes of 100 users, there are 100 QQS
- 【目标检测】YOLOv5跑通VisDrone数据集
猜你喜欢

基于redis6.2.4的redis cluster部署

Data analysis and privacy security become the key factors for the success or failure of Web3.0. How do enterprises layout?

jenkins的文件参数,可以用来上传文件

Briefly describe the implementation principle of redis cluster

第三章、数据类型和变量

谁动了我的内存,揭秘 OOM 崩溃下降 90% 的秘密

简述redis集群的实现原理

Rebudget汇报PPT

7. Dependency injection

Frustrated Internet people desperately knock on the door of Web3
随机推荐
Rebudget汇报PPT
Unity is better to use the hot scheme Wolong
After 20 years of agitation, the chip production capacity has started from zero to surpass that of the United States, which is another great achievement made in China
What is chain game system development? How to make chain game system development
ACL 2022 | 基于最优传输的对比学习实现可解释的语义文本相似性
GTX1080Ti 光纤HDMI干扰出现闪屏1080Ti 闪屏解决方法
Sogou batch push software - Sogou batch push tool [2022 latest]
使用Huggingface在矩池云快速加载预训练模型和数据集
unity 最好用热更方案卧龙 wolong
复旦大学EMBA2022毕业季丨毕业不忘初心 荣耀再上征程
微信公众号开发之消息的自动回复
【知识图谱】实践篇——基于医疗知识图谱的问答系统实践(Part3):基于规则的问题分类
Solution for win10 device management not recognizing gtx1080ti display device
Data analysis and privacy security become the key factors for the success or failure of Web3.0. How do enterprises layout?
Rainbow plug-in extension: monitor MySQL based on MySQL exporter
【目标检测】YOLOv5跑通VOC2007数据集(修复版)
C # introductory basic tutorial
Bo Yun container cloud and Devops platform won the trusted cloud "technology best practice Award"
[book club issue 13] +ffmpeg video capture function
EasyUI DataGrid control uses