2013-04-01 74 views
0

尝试使用Python机械化登录到网页。由于我在找到正确的表单时遇到问题,而不是发布URL(代码可能会更改),所以我会将一些代码复制到此处以供将来用户使用。我读this,但似乎没有一个明确的答案。Python机械化 - 表单提交 - 选择正确的表格

无论如何,我在this tutorial之前完成了所有的机械化工作,直到我获得表格。

当我打电话:

for form in br.forms(): 
    print form 

我回去:

POST https://www.myexample.com/x-www-form-urlencoded 
HiddenControl(utf8=✓) (readonly) 
HiddenControl(authenticity_token=BfqPL1ilOXeg08Or/CEBAiK4duWgncY=  
CheckboxControl(affiliate[remember_me]=[1]) 

望着原始的HTML我看到:

<label for="affiliate_email">Email<./label> 
<.input autofocus="autofocus" id="affiliate_email" 
    name="affiliate[email]" size="30" type="email" /> 

然而,当我尝试选择电子邮件字段我得到一个表单未找到错误。

br.select_form(name="affiliate[email]") 
# updated to 
br.select_form(nr=0) 
# Now what do I do here to enter something into that form? 
br.form['someIDhere']='[email protected]' 

我也尝试过使用表单ID和许多其他可能的表单名称。我不明白为什么使用br.forms()打印表单会返回这些奇怪的结果,这是否意味着该网站正在使用javascript登录表单?

预先感谢您!

回答

0

affiliate[email]不是形式的名称,但形式内的输入的。 尝试使用:

br.select_form(nr=0) 

如果表单没有名称,并在页面上的第一个/唯一形式。

+0

好吧,我总算使用了错误的语法围绕我有一个问题有关的部分,我的意思是br.form [“”](选择的形式,我必须将数据输入之后)。更新了我的帖子。谢谢! – Joker