Python 不使用提交按钮提交,机械化
所以,我从Mechanize开始,显然我首先尝试的是monkey rhino级别的高JavaScript导航站点 现在我一直坚持的是提交表格 通常我会使用Mechanize内置的submit()函数进行提交Python 不使用提交按钮提交,机械化,python,mechanize,Python,Mechanize,所以,我从Mechanize开始,显然我首先尝试的是monkey rhino级别的高JavaScript导航站点 现在我一直坚持的是提交表格 通常我会使用Mechanize内置的submit()函数进行提交 import mechanize browser = mechanize.Browser() browser.select_form(name = 'foo') browser.form['bar'] = 'baz' browser.submit() 通过这种方式,它将使用HTML表单中
import mechanize
browser = mechanize.Browser()
browser.select_form(name = 'foo')
browser.form['bar'] = 'baz'
browser.submit()
通过这种方式,它将使用HTML表单中提供的submit按钮
然而,我所停留的网站必须是一个不使用HTML提交按钮的网站。。。不,他们试图成为JavaScript大师,并通过JavaScript进行提交
通常的submit()似乎不适用于此
所以。。。有没有办法绕过这个问题
感谢您的帮助。非常感谢
--[编辑]--
我一直坚持使用的JavaScript函数:
function foo(bar, baz) {
var qux = document.forms["qux"];
qux.bar.value = bar.split("$").join(":");
qux.baz.value = baz;
qux.submit();
}
我在Python中所做的(以及哪些不起作用):
三种方式:
如果表单是使用POST/GET方法提交的,那么最好使用第一种方法,否则必须使用第二种和第三种方法
import mechanize
import urllib
browser = mechanize.Browser()
#These are the parameters you've got from checking with the aforementioned tools
parameters = {'parameter1' : 'your content',
'parameter2' : 'a constant value',
'parameter3' : 'unique characters you might need to extract from the page'
}
#Encode the parameters
data = urllib.urlencode(parameters)
#Submit the form (POST request). You get the post_url and the request type(POST/GET) the same way with the parameters.
browser.open(post_url,data)
#Submit the form (GET request)
browser.open(post_url + '%s' % data)
import mechanize
import urllib
browser = mechanize.Browser()
#These are the parameters you've got from checking with the aforementioned tools
parameters = {'parameter1' : 'your content',
'parameter2' : 'a constant value',
'parameter3' : 'unique characters you might need to extract from the page'
}
#Encode the parameters
data = urllib.urlencode(parameters)
#Submit the form (POST request). You get the post_url and the request type(POST/GET) the same way with the parameters.
browser.open(post_url,data)
#Submit the form (GET request)
browser.open(post_url + '%s' % data)