开发者

Trying to log into an authenticated website

I am trying to log into a web page and access an authenticated page. It isn't working.

from __future__ import division
from __future__ import unicode_literals
from __future__ import print_function
import re
import mechanize
br = mechanize.Browser()
br.open("https://www.thomsononeim.com/s-log_in.asp")
br.select_form(name="MainForm")
br.form['txtLoginID'] = 开发者_JAVA技巧'Username'
br.form['txtPWD'] = 'Password'
br.submit()

EDIT: I believe the issue is trying to log into a JavaScript page.


You can use urllib and submit post parameters. Ex:

import urllib.parse as urlparse
import urllib.request as urlreq

params = urlparse.urlencode({'txtLoginId':'Username', 'txtPWD':'Password'})

req = urlreq.urlopen("http://www.your-site.com/login.php", params)
page = str(req.read())

page is now a string wich contains source code of the authenticated page.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜