python网络爬虫–简单爬取糗事百科

刚开始学习python爬虫,写了一个简单python程序爬取糗事百科。

具体步骤是这样的:首先查看糗事百科的url:http://www.qiushibaike.com/8hr/page/2/?s=4959489,可以发现page后的数据代表第几页。

然后装配request,注意要设置user_agent

代码语言:javascript代码运行次数:0运行复制

1 user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'2 headers = {'User-Agent': user_agent}3 request=urllib2.Request(url,headers=headers)4 response=urllib2.urlopen(request)

登录后复制

文章来自互联网,只做分享使用。发布者:,转转请注明出处:https://www.dingdanghao.com/article/861959.html

(0)
上一篇 2025-05-09 10:37
下一篇 2025-05-09 10:37

相关推荐

联系我们

在线咨询: QQ交谈

邮件:442814395@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信公众号