开发者

submitting webforms python

I am trying to submit this webform and log into this site: https://www.kalahari.net/profile/pipeline/signin.aspx

I keep getting the login site's source code as output when the script is done,so it seems like all is working (no errors) but it's just not logging in. I can't find what I am doing wrong.Please help. I am using Python 3.1.2, I can't use Mechanize as the code needs to be written in Python 3.x

I think my problem might be the POST url I am posting the login information to, b开发者_高级运维ut I cant seem to figure it out, and what it should be.

f=open("page_src.html",'wb') 
cj=cookiejar.CookieJar()

params=urllib.parse.urlencode({'ctl00$ctl00$cplhMain$cplhContent$txtEmail': 'username', 'ctl00$ctl00$cplhMain$cplhContent$txtPassword': 'pass'})

opener = req.build_opener(req.HTTPCookieProcessor(cj))
opener = urllib.request.FancyURLopener()
page = opener.open("https://www.kalahari.net/profile/pipeline/signin.aspx", params)

profilepage = opener.open("https://www.kalahari.net/profile/pipeline/profile.aspx")
source=profilepage.read()

f.write(source)
f.close()


The site is probably using cookies for the login, so you must too. That means you must save the cookies you get when you log in and send them to the site with each following request.

Check out http.cookiejar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜