如何入门 Python 爬虫

\u5982\u4f55\u5165\u95e8 Python \u722c\u866b

\u4e2a\u4eba\u89c9\u5f97\uff1a
\u65b0\u624b\u5b66\u4e60python\u722c\u53d6\u7f51\u9875\u5148\u7528\u4e0b\u97624\u4e2a\u5e93\u5c31\u591f\u4e86\uff1a\uff08\u7b2c4\u4e2a\u662f\u5b9e\u5728\u641e\u4e0d\u5b9a\u7528\u7684\uff0c\u5f53\u7136\u67d0\u4e9b\u7279\u6b8a\u60c5\u51b5\u5b83\u4e5f\u53ef\u80fd\u641e\u4e0d\u5b9a\uff09

1. \u6253\u5f00\u7f51\u9875\uff0c\u4e0b\u8f7d\u6587\u4ef6\uff1aurllib
2. \u89e3\u6790\u7f51\u9875\uff1aBeautifulSoup\uff0c\u719f\u6089JQuery\u7684\u53ef\u4ee5\u7528Pyquery
3. \u4f7f\u7528Requests\u6765\u63d0\u4ea4\u5404\u79cd\u7c7b\u578b\u7684\u8bf7\u6c42\uff0c\u652f\u6301\u91cd\u5b9a\u5411\uff0ccookies\u7b49\u3002
4. \u4f7f\u7528Selenium\uff0c\u6a21\u62df\u6d4f\u89c8\u5668\u63d0\u4ea4\u7c7b\u4f3c\u7528\u6237\u7684\u64cd\u4f5c\uff0c\u5904\u7406js\u52a8\u6001\u4ea7\u751f\u7684\u7f51\u9875

\u8fd9\u51e0\u4e2a\u5e93\u6709\u5b83\u4eec\u5404\u81ea\u7684\u529f\u80fd\u3002\u914d\u5408\u8d77\u6765\u5c31\u53ef\u4ee5\u5b8c\u6210\u722c\u53d6\u5404\u79cd\u7f51\u9875\u5e76\u5206\u6790\u7684\u529f\u80fd\u3002\u5177\u4f53\u7684\u7528\u6cd5\u53ef\u4ee5\u67e5\u4ed6\u4eec\u7684\u5b98\u7f51\u624b\u518c(\u4e0a\u9762\u6709\u94fe\u63a5)\u3002

\u505a\u4e8b\u60c5\u662f\u8981\u6709\u9a71\u52a8\u7684\uff0c\u5982\u679c\u4f60\u6ca1\u4ec0\u4e48\u7279\u522b\u60f3\u6293\u53d6\u7684\uff0c\u65b0\u624b\u5b66\u4e60\u53ef\u4ee5\u4ece\u8fd9\u4e2a\u95ef\u5173\u7f51\u7ad9\u5f00\u59cb
\uff0c\u76ee\u524d\u66f4\u65b0\u5230\u7b2c\u4e94\u5173\uff0c\u95ef\u8fc7\u524d\u56db\u5173\uff0c\u4f60\u5e94\u8be5\u5c31\u638c\u63e1\u4e86\u8fd9\u4e9b\u5e93\u7684\u57fa\u672c\u64cd\u4f5c\u3002

\u5b9e\u5728\u95ef\u4e0d\u8fc7\u53bb\uff0c\u518d\u5230\u8fd9\u91cc\u770b\u9898\u89e3\u5427\uff0c\u7b2c\u56db\u5173\u4f1a\u7528\u5230\u5e76\u884c\u7f16\u7a0b\u3002\uff08\u4e32\u884c\u7f16\u7a0b\u5b8c\u6210\u7b2c\u56db\u5173\u4f1a\u5f88\u8d39\u65f6\u95f4\u54e6\uff09\uff0c\u7b2c\u56db\uff0c\u4e94\u5173\u53ea\u51fa\u4e86\u9898\uff0c\u8fd8\u6ca1\u53d1\u5e03\u9898\u89e3\u3002\u3002\u3002

\u5b66\u5b8c\u8fd9\u4e9b\u57fa\u7840\uff0c\u518d\u53bb\u5b66\u4e60scrapy\u8fd9\u4e2a\u5f3a\u5927\u7684\u722c\u866b\u6846\u67b6\u4f1a\u66f4\u987a\u4e9b\u3002\u8fd9\u91cc\u6709\u5b83\u7684\u4e2d\u6587\u4ecb\u7ecd\u3002

\u8fd9\u662f\u6211\u5728\u77e5\u4e4e\u7684\u56de\u7b54\uff0c\u76f4\u63a5\u8f6c\u8fc7\u6765\u6709\u4e9b\u94fe\u63a5\u6ca1\u6709\u751f\u6548\uff0c\u53ef\u4ee5\u5230\u8fd9\u91cc\u770b\u539f\u7248\uff0chttp://www.zhihu.com/question/20899988/answer/59131676

\u5982\u4f55\u5165\u95e8 python \u722c\u866b
\u5148\u81ea\u5df1\u7b54\u4e00\u4e2a\uff0c\u671f\u5f85\u725b\u4eba\u7684\u56de\u7b54\u3002

\u81ea\u5df1\u5b66Python\u4e0d\u4e45\uff0c\u5217\u4e3e\u81ea\u5df1\u505a\u8fc7\u7684\u548c\u77e5\u9053\u7684\u3002

1. Python\u505a\u722c\u866b\u5f88\u65b9\u4fbf\uff0c\u6709\u73b0\u6210\u7684\u5e93\u3002 \u6211\u5728\u5b66\u4e60python\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u9047\u5230\u8fc7\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u4ee3\u7801\uff1apython/primer/20/Cralwer.py at master \u00b7 xxg1413/python \u00b7 GitHub \u3002\u597d\u50cf\u6709\u5f00\u6e90\u7684\u9879\u76ee\u53eb\u4ec0\u4e48supercrawler\uff0c\u5177\u4f53\u53ef\u4ee5\u770b\u770b\u3002

2.Python\u505a\u6e38\u620f\u3002Pygame\u8fd8\u662f\u4e0d\u9519\u7684\uff0c\u4f46\u53ea\u9002\u5408\u505a\u5c0f\u6e38\u620f\u3002\u7528Pygame\u5199\u4e2a\u690d\u7269\u5927\u6218\u50f5\u5c38\u8fd8\u662f\u53ef\u4ee5\u7684\u3002\u63a8\u8350\u6559\u7a0b \u7528Python\u548cPygame\u5199\u6e38\u620f\u3002Python\u5728\u6e38\u620f\u670d\u52a1\u5668\u65b9\u9762\u4e5f\u6709\u5e94\u7528\u3002EVE\u8fd9\u79cd\u6e38\u620f\u90fd\u5927\u91cf\u7528Python\u3002

3.Python\u4f5c\u4e3a\u9ed1\u5ba2\u7b2c\u4e00\u8bed\u8a00\uff0c\u5728\u9ed1\u5ba2\u9886\u57df\u7684\u5e94\u7528\u5c31\u4e0d\u591a\u8bf4\u4e86\u3002

4.Python\u505a\u7f51\u7ad9\uff0c\u6709\u51e0\u4e2aweb\u6846\u67b6 WebFrameworks\u3002 \u7528\u5f97\u6700\u591a\u7684\u662fDjango\u3002

5......\u5404\u65b9\u9762\u90fd\u6709\uff0c\u4ec0\u4e48\u63a8\u8350\u7cfb\u7edf\uff0c\u90fd\u662f\u7528python\uff0c\u5728\u6b64\u5c31\u4e0d\u4e00\u4e00\u5217\u4e3e\u4e86\u3002

入门的话,我的经历:
1.先用python写一个爬取网页源代码的爬虫(最先是爬取个人博客,会遇到乱码问题当时困扰了很久)

2.后来写了爬取百度图片的程序,自动下载小说(我爱看小说-_-)(接触正则表达式)
3.然后百度图片他那种分页模式,一般一页只有20张左右的图片,分析源代码,完善爬取程序,不受到限制,一次可以下几千张(图片有的是原图,有的是缩略图)
4.后来发现程序卡顿,就添加了多线程。
5.然后模拟登陆一些不用验证码的网页(我学校的oj),cookie登陆B站(本来想写一个抢楼的脚本的,后来发现抢楼的被封号了-_-,就放弃了)

对于使用的库,python2 与 python3 有点不同,我学的是python3
先用的是urllib.request,后来用requests(第三方库),在后来接触Scrapy(也是第三方库)
现在因为事情多了,就把python放下了,准备寒假写一些脚本,毕竟python不会有期末考试...

我的个人经历,希望可以帮到你。

网上有很多例子啊 随便找一个照着实现一下

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网