码迷,mamicode.com
首页 > 其他好文 > 详细

爬虫学习

时间:2016-11-04 07:35:52      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:div   proc   uil   bsp   sso   imp   import   com   blog   

#coding:utf8
__author__ = wang
import urllib2
import cookielib

url = "http://www.baidu.com";

response = urllib2.urlopen(url)
print(len(response.read()));


request = urllib2.Request(url)
request.add_header(user-agent,Mozilla/5.0)
response1 = urllib2.urlopen(request)
print len(response1.read())

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
response2 = urllib2.urlopen(url)
print cj
print len(response2.read())

 

爬虫学习

标签:div   proc   uil   bsp   sso   imp   import   com   blog   

原文地址:http://www.cnblogs.com/php-linux/p/6028902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!