<p> </p> <h2>五、 响应Response</h2> <p><strong>1、响应状态码</strong></p> <p><strong> </strong>200:代表成功</p> <p> 301:代表跳转</p> <p> 404:文件不存在</p> <p> 403:无权限访问</p> <p> 502:服务器错误</p> <p> </p> <p><strong>2、respone header</strong></p> <p><br><strong>响应头需要注意的参数:</strong></p> <p>(1)Set-Cookie:BDSVRTM=0; path=/:可能有多个,是来告诉浏览器,把cookie保存下来</p> <p>(2)Content-Location:服务端响应头中包含Location返回浏览器之后,浏览器就会重新访问另一个页面</p> <p> </p> <p> </p> <p><strong>3、preview就是网页源代码</strong></p> <p>JSO数据</p> <p>如网页html,图片</p> <p>二进制数据等 </p> <p> </p> <p> </p> <h2>六、总结</h2> <p><strong>1、总结爬虫流程:</strong></p> <p> 爬取--->解析--->存储</p> <p> </p> <p><strong>2、爬虫所需工具:</strong></p> <p> 请求库:requests,selenium(可以驱动浏览器解析渲染CSS和JS,但有性能劣势(有用没用的网页都会加载);)<br> 解析库:正则,beautifulsoup,pyquery<br> 存储库:文件,MySQL,Mongodb,Redis</p> <p> </p> <p><strong>3、爬获校花网</strong></p> <p>最后送给大家点福利吧<img src="https://images2017.cnblogs.com/blog/1122865/201711/1122865-20171109204929981-337261501.png" alt=""></p> <p>基础版:</p> <div class="cnblogs\_code"><img id="code\_img\_closed\_b538ac40-f10a-4f5c-a7ae-424a41681d7a" class="code\_img\_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""> <span class="cnblogs\_code\_collapse">View Code</span></div> <p> </p> <p>函数封装版</p> <div class="cnblogs\_code"><img id="code\_img\_closed\_190a9b5e-8166-4d91-a8ae-c147f0a3cde3" class="code\_img\_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""> <span class="cnblogs\_code\_collapse">View Code</span></div> <p> </p> <p>并发版(如果一共需要爬30个视频,开30个线程去做,花的时间就是 其中最慢那份的耗时时间)</p> <div class="cnblogs\_code"><img id="code\_img\_closed\_e4f47d03-54d0-4afb-afa7-8e86c5a1b5a8" class="code\_img\_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""> <span class="cnblogs\_code\_collapse">View Code</span></div> <p> </p> <p><strong>涉及知识:多线程多进程</strong></p> <p>计算密集型任务:使用多进程,因为能Python有GIL,多进程可以利用上CPU多核优势;</p> <p>IO密集型任务:使用多线程,做IO切换节省任务执行时间(并发)</p> <p>线程池</p> <p> </p> <p> </p> <p>参考博客:</p> <p>瞎驴<a href="http://www.cnblogs.com/linhaifeng/articles/7773496.html" target="\_blank">http://www.cnblogs.com/linhaifeng/articles/7773496.html</a></p> </div> <div id="cnblogs\_post\_body" class="blogpost-body "> <p><a href="https://github.com/Chyroc/WechatSogou" rel="nofollow" target="\_blank">WechatSogou</a> \[1\]- 微信公众号爬虫。基于搜狗微信搜索的微信公众号爬虫接口,可以扩展成基于搜狗搜索的爬虫,返回结果是列表,每一项均是公众号具体信息字典。</p> <p><a href="https://github.com/lanbing510/DouBanSpider" rel="nofollow" target="\_blank">DouBanSpider</a> \[2\]- 豆瓣读书爬虫。可以爬下豆瓣读书标签下的所有图书,按评分排名依次存储,存储到Excel中,可方便大家筛选搜罗,比如筛选评价人数>1000的高分书籍;可依据不同的主题存储到Excel不同的Sheet ,采用User Agent伪装为浏览器进行爬取,并加入随机延时来更好的模仿浏览器行为,避免爬虫被封。</p> <p><a href="https://github.com/LiuRoy/zhihu\_spider" rel="nofollow" target="\_blank">zhihu\_spider</a> \[3\]- 知乎爬虫。此项目的功能是爬取知乎用户信息以及人际拓扑关系,爬虫框架使用scrapy,数据存储使用mongo。</p> <p><a href="https://github.com/airingursb/bilibili-user" rel="nofollow" target="\_blank">bilibili-user</a> \[4\]- Bilibili用户爬虫。总数据数:20119918,抓取字段:用户id,昵称,性别,头像,等级,经验值,粉丝数,生日,地址,注册时间,签名,等级与经验值等。抓取之后生成B站用户数据报告。</p> <p><a href="https://github.com/LiuXingMing/SinaSpider" rel="nofollow" target="\_blank">SinaSpider</a> \[5\]- 新浪微博爬虫。主要爬取新浪微博用户的个人信息、微博信息、粉丝和关注。代码获取新浪微博Cookie进行登录,可通过多账号登录来防止新浪的反扒。主要使用 scrapy 爬虫框架。</p> <p><a href="https://github.com/gnemoug/distribute\_crawler" rel="nofollow" target="\_blank">distribute\_crawler</a> \[6\]- 小说下载分布式爬虫。使用scrapy,Redis, MongoDB,graphite实现的一个分布式网络爬虫,底层存储mongodb集群,分布式使用redis实现,爬虫状态显示使用graphite实现,主要针对一个小说站点。</p> <p><a href="https://github.com/yanzhou/CnkiSpider" rel="nofollow" target="\_blank">CnkiSpider</a> \[7\]- 中国知网爬虫。设置检索条件后,执行src/CnkiSpider.py抓取数据,抓取数据存储在/data目录下,每个数据文件的第一行为字段名称。</p> <p><a href="https://github.com/lanbing510/LianJiaSpider" rel="nofollow" target="\_blank">LianJiaSpider</a> \[8\]- 链家网爬虫。爬取北京地区链家历年二手房成交记录。涵盖链家爬虫一文的全部代码,包括链家模拟登录代码。</p> <p><a href="https://github.com/taizilongxu/scrapy\_jingdong" rel="nofollow" target="\_blank">scrapy\_jingdong</a> \[9\]- 京东爬虫。基于scrapy的京东网站爬虫,保存格式为csv。</p> <p><a href="https://github.com/caspartse/QQ-Groups-Spider" rel="nofollow" target="\_blank">QQ-Groups-Spider</a> \[10\]- QQ 群爬虫。批量抓取 QQ 群信息,包括群名称、群号、群人数、群主、群简介等内容,最终生成 XLS(X) / CSV 结果文件。</p> <p><a href="https://github.com/hanc00l/wooyun\_public" rel="nofollow" target="\_blank">wooyun\_public</a>\[11\]-乌云爬虫。 乌云公开漏洞、知识库爬虫和搜索。全部公开漏洞的列表和每个漏洞的文本内容存在mongodb中,大概约2G内容;如果整站爬全部文本和图片作为离线查询,大概需要10G空间、2小时(10M电信带宽);爬取全部知识库,总共约500M空间。漏洞搜索使用了Flask作为web server,bootstrap作为前端。</p> <p><a href="https://github.com/lining0806/QunarSpider" rel="nofollow" target="\_blank">QunarSpider</a> \[12\]- 去哪儿网爬虫。 网络爬虫之Selenium使用代理登陆:爬取去哪儿网站,使用selenium模拟浏览器登陆,获取翻页操作。代理可以存入一个文件,程序读取并使用。支持多进程抓取。</p> <p><a href="https://github.com/fankcoder/findtrip" rel="nofollow" target="\_blank">findtrip</a> \[13\]- 机票爬虫(去哪儿和携程网)。Findtrip是一个基于Scrapy的机票爬虫,目前整合了国内两大机票网站(去哪儿 + 携程)。</p> <p><a href="https://github.com/leyle/163spider" rel="nofollow" target="\_blank">163spider</a> \[14\] - 基于requests、MySQLdb、torndb的网易客户端内容爬虫</p> <p><a href="https://github.com/dontcontactme/doubanspiders" rel="nofollow" target="\_blank">doubanspiders</a>\[15\]- 豆瓣电影、书籍、小组、相册、东西等爬虫集</p> <p><a href="https://github.com/LiuXingMing/QQSpider" rel="nofollow" target="\_blank">QQSpider</a> \[16\]- QQ空间爬虫,包括日志、说说、个人信息等,一天可抓取 400 万条数据。</p> <p><a href="https://github.com/Shu-Ji/baidu-music-spider" rel="nofollow" target="\_blank">baidu-music-spider</a> \[17\]- 百度mp3全站爬虫,使用redis支持断点续传。</p> <p><a href="https://github.com/pakoo/tbcrawler" rel="nofollow" target="\_blank">tbcrawler</a>\[18\]- 淘宝和天猫的爬虫,可以根据搜索关键词,物品id来抓去页面的信息,数据存储在mongodb。</p> <p><a href="https://github.com/benitoro/stockholm" rel="nofollow" target="\_blank">stockholm</a> \[19\]- 一个股票数据(沪深)爬虫和选股策略测试框架。根据选定的日期范围抓取所有沪深两市股票的行情数据。支持使用表达式定义选股策略。支持多线程处理。保存数据到JSON文件、CSV文件。</p> <p><a href="https://github.com/k1995/BaiduyunSpider" rel="nofollow" target="\_blank">BaiduyunSpider</a>\[20\]-百度云盘爬虫。 </p> <p><a href="http://link.zhihu.com/?target=https%3A//github.com/Qutan/Spider" rel="nofollow" target="\_blank">Spider\[21\]</a>-社交数据爬虫。支持微博,知乎,豆瓣。</p> <p><a href="http://link.zhihu.com/?target=https%3A//github.com/Qutan/Spider" rel="nofollow" target="\_blank">proxy pool\[22\]</a>-Python爬虫代理IP池(proxy pool)。</p> <p><a href="http://link.zhihu.com/?target=https%3A//github.com/RitterHou/music-163" rel="nofollow" target="\_blank">music-163\[23\]</a>-爬取网易云音乐所有歌曲的评论。</p> <p><a href="http://link.zhihu.com/?target=https%3A//github.com/RitterHou/music-163" rel="nofollow" target="\_blank">jandan\_spider\[24\]</a>-爬取煎蛋妹纸图片。</p> <p><a href="http://link.zhihu.com/?target=https%3A//github.com/jackgitgz/CnblogsSpider" rel="nofollow" target="\_blank">CnblogsSpider\[25\]</a>-cnblogs列表页爬虫。</p> <p><a href="http://link.zhihu.com/?target=https%3A//github.com/jackgitgz/CnblogsSpider" rel="nofollow" target="\_blank">spider\_smooc\[26\]</a>-爬取慕课网视频。</p> <p><a href="http://link.zhihu.com/?target=https%3A//github.com/yanzhou/CnkiSpider" rel="nofollow" target="\_blank">CnkiSpider\[27\]</a>-中国知网爬虫。</p> <p><a href="http://link.zhihu.com/?target=https%3A//github.com/littlethunder/knowsecSpider2" rel="nofollow" target="\_blank">knowsecSpider2\[28\]</a>-知道创宇爬虫题目。</p> <p><a href="http://link.zhihu.com/?target=https%3A//github.com/x-spiders/aiss-spider" rel="nofollow" target="\_blank">aiss-spider\[29\]</a>-爱丝APP图片爬虫。</p> <p><a href="https://github.com/szcf-weiya/SinaSpider" rel="nofollow" target="\_blank">SinaSpider\[30\]</a>-动态IP解决新浪的反爬虫机制,快速抓取内容。</p> <p><a href="http://link.zhihu.com/?target=https%3A//github.com/Kevinsss/csdn-spider" rel="nofollow" target="\_blank">csdn-spider\[31\]</a>-爬取CSDN上的博客文章。</p> <p><a href="http://link.zhihu.com/?target=https%3A//github.com/changetjut/ProxySpider" rel="nofollow" target="\_blank">ProxySpider\[32\]</a>-爬取西刺上的代理IP,并验证代理可用性。</p> <p><a href="https://github.com/GuozhuHe/webspider" rel="nofollow" target="\_blank">webspider\[33\]</a>-本系统是一个主要使用python3, celery和requests来爬取职位数据的爬虫,实现了定时任务,出错重试,日志记录,自动更改Cookies等的功能,并使用ECharts + Bootstrap 来构建前端页面,来展示爬取到的数据。</p> </div>1ps: 21、登录窗口,文件上传等,信息都会被附加到请求体内 32、登录,输入错误的用户名密码,然后提交,就可以看到post,正确登录后页面通常会跳转,无法捕捉到post</pre>
Python爬虫原理与python爬虫实例大全
Stella981
2021-10-11
1376 0 0
点赞
收藏
评论区
加载中...