Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python机械化javascript提交按钮问题!_Python_Mechanize_Urlopen - Fatal编程技术网

python机械化javascript提交按钮问题!

python机械化javascript提交按钮问题!,python,mechanize,urlopen,Python,Mechanize,Urlopen,我正在用mechanize.browser模块编写一些脚本 其中一个问题是所有其他事情都可以,但当提交()表单时,它不起作用 所以我发现了一些可疑的来源部分 在html源代码中,我发现如下所示 我在想,在提交表单时,登录检查(这个)制造问题 但是如何使用mechanize模块处理这种javascript函数,我可以 是否已成功提交表单并可以接收结果 以下是与loginCheck(此)javascript函数相关的websource代码段 function init(){

我正在用mechanize.browser模块编写一些脚本

其中一个问题是所有其他事情都可以,但当提交()表单时,它不起作用

所以我发现了一些可疑的来源部分

在html源代码中,我发现如下所示

我在想,在提交表单时,登录检查(这个)制造问题

但是如何使用mechanize模块处理这种javascript函数,我可以

是否已成功提交表单并可以接收结果

以下是与loginCheck(此)javascript函数相关的websource代码段

        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";
    }
我知道mechanize不支持javascript,所以我想做一个progammalylogincheck()

函数与python mechanize代码一起使用

谁能帮我把这个javascript函数变成python的机械化

翻译代码

那么正确的登录网站可以吗

多谢

    # -*- 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()

如果有人能帮我…非常感谢

您可以在浏览器中手动完成登录过程,并检查(使用firefox中的Firebug、Chrome中的开发者工具等)当您点击“确定”按钮时向站点发送的请求。通常这是一个POST请求,数据取自登录表单。检查此请求中发送的数据,并使用以下命令执行您自己的post请求:

mechanize.urlopen(URL, POST_DATA). 
您可以使用以下方法从mechanize的表单对象提取POST_数据(和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)

请告诉我这些只是伪用户/传递字符串。如果这样做会产生
urllib2.HTTPError:HTTP Error 414:Request URI太大
,但请求在普通浏览器中工作正常,该怎么办?