- 论坛徽章:
- 0
|
请教各位大侠这段代码哪里出的问题,为什么总是登录不进去
import urllib2
import cookielib
#from BeautifulSoup import BeautifulSoup,BeautifulStoneSoup
header = {'User-Agent':'Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2'}
username = 'XXX'
password = 'XXX'
cookie = cookielib.CookieJar()
cookieProc = urllib2.HTTPCookieProcessor(cookie)
opener = urllib2.build_opener(cookieProc)
urllib2.install_opener(opener)
login_data = urllib.urlencode({'username' : username, 'password' : password})
try:
req=urllib2.Request(url='https://auth.dxy.cn/login?null',data=login_data,headers=header)
res = urllib2.urlopen(req).read()
except URLError, error:
print error
print urllib2.urlopen(req).geturl() |
|