模拟登陆
# -*- coding: UTF-8 -*- #python 2.7 #xiaodeng import urllib,urllib2,cookielib import string,re urllib.getproxies_registry=lambda:{} #url url ="https://www.douban.com/accounts/login" #headers headers = {'User-Agent' : 'Mozilla/5.0(Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/34.0.1847.116 Safari/537.36',} #data postData = { 'login':'登录', 'captcha-id':'XjvblSqv8Nj7UZWssiZGpB7r', 'captcha-solution':'sister', 'form_email':'13826189540', 'form_password':'dyg911120' } #data编码 postData =urllib.urlencode(postData) #加cookie cj = cookielib.LWPCookieJar() cookie_support =urllib2.HTTPCookieProcessor(cj) opener =urllib2.build_opener(cookie_support,urllib2.HTTPHandler) urllib2.install_opener(opener) h = urllib2.urlopen(url) #发送请求带上url、postData、headers request =urllib2.Request(url,postData,headers)#这里的url一定要是登录的地址 #接收返回结果 response =urllib2.urlopen(request).read() print response
无语言基础,自学python所做的各种笔记,欢迎大牛指点.