开发者

mechanize can't login python

I'm making auto-login script by use mechanize python.

Before I was used mechanize with no problem, but www.gmarket.co.kr in this site I couldn't make it .

whenever i try to login always login page was returned even with correct gmarket id , pass, i can't login and I saw some suspicious message

"<script language=javascript>top.location.reload();</script>"

I think this related with my problem, but don't know exactly how to handle . Here is sample id and pass for login test

id: tgi177 pass: tk1047

if anyone can help me much appreciate thanks in advance

CODE:

# -*- coding: cp949 -*-
from lxml.html import parse, fromstring
import sys,os
import mechanize, urllib
import cookielib
import re
from BeautifulSoup import BeautifulSoup,BeautifulStoneSoup,Tag

try:

    params = urllib.urlencode({'command':'login',
                               'url':'h开发者_运维技巧ttp%3A%2F%2Fwww.gmarket.co.kr%2F',
                               'member_type':'mem',
                               'member_yn':'Y',
                               'login_id':'tgi177',
                               'image1.x':'31',
                               'image1.y':'26',
                               'passwd':'tk1047',
                               'buyer_nm':'',
                               'buyer_tel_no1':'',
                               'buyer_tel_no2':'',
                               'buyer_tel_no3':''

                               })
    rq = mechanize.Request("http://www.gmarket.co.kr/challenge/login.asp")
    rs = mechanize.urlopen(rq)
    data = rs.read()    


    logged_in = r'input_login_check_value'  in data                                    
    if logged_in:
        print ' login success !'  
        rq = mechanize.Request("http://www.gmarket.co.kr") 
        rs = mechanize.urlopen(rq)
        data = rs.read()   
        print data  

    else:
        print 'login failed!'
        pass
        quit()      
except:
    pass


mechanize doesn't have the ability to interact with JavaScript. Probably spidermonkey module will help you (I have no experience with it, but description is quite promising). Also you could handle such reload (e.g.Browser.reload() for this particular case) manually if it's the only site you have this problem.

Update: Quick look through your page shows that you have submit to other URL (with https: scheme). Look through checkValid() JavaScript function. Posting to it gives other result. Note, that this looks like homework you should do yourself before asking.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜