首页 > 代码库 > python爬虫之urllib
python爬虫之urllib
#POST import urllib import urllib2 values = {} values[‘username‘] = "1016903103@qq.com" values[‘password‘] = "XXXX" data = urllib.urlencode(values) url = "http://passport.csdn.net/account/login?from=http://my.csdn.net/my/mycsdn" request = urllib2.Request(url,data) response = urllib2.urlopen(request) print response.read() #GET import urllib import urllib2 values={} values[‘username‘] = "1016903103@qq.com" values[‘password‘]="XXXX" data = urllib.urlencode(values) url = "http://passport.csdn.net/account/login" geturl = url + "?"+data request = urllib2.Request(geturl) response = urllib2.urlopen(request) print response.read() #headers import urllib import urllib2 url = ‘http://www.server.com/login‘ user_agent = ‘Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)‘ values = {‘username‘ : ‘cqc‘, ‘password‘ : ‘XXXX‘ } headers = { ‘User-Agent‘ : user_agent } data = urllib.urlencode(values) request = urllib2.Request(url, data, headers) response = urllib2.urlopen(request) page = response.read()
python爬虫之urllib
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。