Python机器人JavaScript提交按钮问题!

2024-05-12 23:34:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用mechanize.browser模块制作一些脚本。

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

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

在html源代码中,我被发现如下。

我在想,在提交表单时,loginCheck(这个)会产生问题。

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

提交表单成功,是否可以接收结果?

下面是与loginCheck(this)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,所以我想让progammetally loginCheck()

使用python机械化代码执行函数。

有谁能帮我把这个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()

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


Tags: 函数brimportidtruehttp表单html