码迷,mamicode.com
首页 > 编程语言 > 详细

python爬虫之urllib

时间:2017-03-15 12:37:36      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:rom   com   login   name   www   sdn   count   csdn   url   

#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

标签:rom   com   login   name   www   sdn   count   csdn   url   

原文地址:http://www.cnblogs.com/wangbin2188/p/6553238.html

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