开发者

web access by python

i'am looking up for way to enter web site "Login"

i tried this

login_form_seq = [
      ('user', 'Lick'),
      ('pass', 'Shot'),
      ('submit', 'login')]
A=urllib.urlencode(login_form_seq)
opener = urllib2.build_opener()
try:
 site = opener.open('http://www.SMS-Example.com/user.php', A).read()
 site2 = urllib.urlopen('http://www.SMS-Example.com/sm开发者_运维知识库s.php').read()
 print site2
except(urllib2.URLError), msg:
 print msg
 site = ""
 pass

but actually what I should put on submit and login? i put it randomly !!

thanks...


It will depend from site to site and on many site you won't even need a submit value, user/pass should be sufficient and then in many other sites they may have some hidden fields in the login form, so best way is to see the fields in the form you are submitting either directly in html or using some tool like firebug.

Other thing you must know is that logging thru one http request doesn't enable login for next http request, for that you will need to track cookies, which is not very easy but not very difficult task.

Instead you can just use twill or mechanize


Really depends. Usually programmers discards value of a submit button, setting its value to something meaningful, but it isn't set in stone. In your case 'login' is the name of a button control, 'login' is its value and it will be the button's label and would be discarded with 99% probability.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜