如何使用mechanize python填写表单

时间:2014-07-23 18:46:01

标签: python python-2.7 mechanize mechanize-python

我正在写一个登录网站的脚本,我想填写表格。我可以毫无问题地填写登录表单,但我不确定如何在登录后填写实际表格。下面是我用来访问表单的代码:我想访问的表单由三个在页面之间导航的选项卡组成。

import mechanize
op = mechanize.Browser() # use mecahnize's browser
op.set_handle_robots(False)
url= "http://example.com"
op.open(url)
email = raw_input("Username: ") #ask for username
password = raw_input("Password: ") #ask for password

op.select_form(nr=0) #python labels forms 0,1,2,3 etc. since there is only 1 form, just select 0

op.form["loginForm:user"] = email
op.form["loginForm:pw"] = password
op.submit()

for i in op.forms():
   print i

此代码打印出来:我更改了url并用x替换了实际的javax.faces,以保护原始代码。当我在表单上使用Chrome检查元素时,这里不显示字段。这是怎么回事?

<NavForm POST https://someurl.xhtml application/x-www-form-   urlencoded
<HiddenControl(NavForm=NavForm) (readonly)>
<HiddenControl(javax.faces.ViewState=XXXX) (readonly)>>

0 个答案:

没有答案