Problem with python mechanize javascript submit!

im creating some script with mechanize.browser module.

one of the problems is everything else, everything is fine, but when the submit () form, it does not work,

therefore, I found a part of the source of suspicion.

in the html source I was found such as the following.

im thinking, loginCheck (this) creates a problem when submitting the form.

but how to handle such a javascript function with a mechanization module, so I can

successfully send the form and get the result?

Below is the websource snippet associated with the loginCheck (this) javascript function.

        function init(){
        FRMLOGIN.ID.focus();
    }

    function loginCheck(f){
        if(chkNull(f.ID, "아이디를"))
            return false;

        if(chkNull(f.PWD, "패스워드를"))
            return false;

        //f.target = "ifrmLoginHidden";
        f.action = (f.SECCHK.checked) ? "https://user.buddybuddy.co.kr/Login/Login.asp" : "http://user.buddybuddy.co.kr/Login/Login.asp";
    }

I know that mechanization does not support javascript, so I want to do progammatically loginCheck ()

with python mechanization code.

Can anyone help me make this javascript function for python mechanization

translated code?

?

!

    # -*- coding: cp949-*-
import sys,os
import mechanize, urllib
import cookielib
from BeautifulSoup import BeautifulSoup,BeautifulStoneSoup,Tag
import datetime, time, socket
import re,sys,os,mechanize,urllib,time


br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

# Browser options
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)

# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

# Want debugging messages?
br.set_debug_http(True)
br.set_debug_redirects(True)
br.set_debug_responses(True)

# User-Agent (this is cheating, ok?)
br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.6')]
br.open('http://user.buddybuddy.co.kr/Login/LoginForm.asp?URL=')
html = br.response().read()
print html

br.select_form(name='FRMLOGIN')
print br.viewing_html()
br.form['ID']='psh7943'
br.form['PWD']='qkrthgus'
br.submit()

print br.response().read()

- .. !!

+3
1

(, , Firebug Firefox, Chrome ..), "". POST , . , :

mechanize.urlopen(URL, POST_DATA). 

POST_DATA ( post_url) , :

form.click_request_data()

.

:

br.select_form(name='form_name')
br.form['login']='login'
br.form['pass']='pass'
post_url, post_data, headers =  br.form.click_request_data()
mechanize.urlopen(post_url, post_data)
+4

Source: https://habr.com/ru/post/1766632/


All Articles