刚开始学习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
