我试图用python登录到一个网站,因为我要收集的一些数据需要登录。我的问题是,无论我如何编写代码,我都无法使登录脚本正常工作。。在
我的登录脚本代码如下:
import requests
import cookielib
import urllib
import urllib2
url = 'https://www.lectio.dk/lectio/94/login.aspx?lecafdeling=4733693087'
values = {'m_Content_username2' : '12z01',
'm_Content_password2' : 'password', }
data = urllib.urlencode(values)
cookies = cookielib.CookieJar()
opener = urllib2.build_opener(
urllib2.HTTPRedirectHandler(),
urllib2.HTTPHandler(debuglevel=0),
urllib2.HTTPSHandler(debuglevel=0),
urllib2.HTTPCookieProcessor(cookies))
response = opener.open(url, data)
the_page = response.read()
http_headers = response.info()
loggedin = requests.get('https://www.lectio.dk/lectio/94/forside.aspx')
print loggedin.content
我也尝试了这个代码,我想我可能更喜欢使用:
^{pr2}$他们都不管用。。。 我尝试登录的网站的html如下:
<input name="m$Content$username2" type="text" id="m_Content_username2" style="width: 130px" maxlength="20" onkeypress="capsDetect(event)" onkeyup="capsToggle(event)" onblur="capsReset(event)" autocomplete="off">
<input name="m$Content$password2" type="password" id="m_Content_password2" style="width: 130px" maxlength="50" onkeypress="capsDetect(event)" onkeyup="capsToggle(event)" onblur="capsReset(event)" autocomplete="off">
希望有人能帮我。。非常感谢。在
你需要这样的东西:
您可能还需要添加一些头,比如User Agent,我可能会错过一些CSRF和ASP.NET发布值。试试看。在
添加邮件头:
^{pr2}$相关问题 更多 >
编程相关推荐