简体   繁体   English

斜纹提交功能不适用于表格

[英]Twill submit function not working with form

I am trying to write a crawler with twill for a page, and it requires me to login. 我正在尝试为页面编写带有斜纹的履带,并且需要我登录。 I can fill in the form. 我可以填写表格。 But the submit() function of twill does not seem to "click" the button. 但是斜纹的submit()函数似乎并未“单击”按钮。

Form name=fSSUser_Logon (#1)
## ## __Name__________________ __Type___ __ID________ __Value__________________
1     TFORM                    hidden    TFORM        SSUser.Logon 
2     TPAGID                   hidden    TPAGID       SRLpKQyn1yc8 
3     TEVENT                   hidden    TEVENT        
4     TXREFID                  hidden    TXREFID      2 
5     TOVERRIDE                hidden    TOVERRIDE     
6     TDIRTY                   hidden    TDIRTY       1 
7     TWKFL                    hidden    TWKFL         
8     TWKFLI                   hidden    TWKFLI        
9     TFRAME                   hidden    TFRAME        
10    TWKFLL                   hidden    TWKFLL        
11    TWKFLJ                   hidden    TWKFLJ        
12    TREPORT                  hidden    TREPORT       
13    TRELOADCMP               hidden    TRELOADCMP    
14    TRELOADID                hidden    TRELOADID    SRLpKQy1nyc7 
15    TOVERLAY                 hidden    TOVERLAY      
16    RELOGON                  hidden    RELOGON       
17    USERNAME                 text      USERNAME      
18    PASSWORD                 password  PASSWORD      
19    Logon                    button    Logon        Logon 

showforms() on the page as above. 如上页面上的showforms()。

And the actual code for the button is the following: 该按钮的实际代码如下:

<input type="button" class="clsButton" id="Logon" name="Logon" tabindex="3" value="Logon" title="Logon">

It does not have any formaction I can use. 它没有我可以使用的任何formaction。

My code thus far: 到目前为止,我的代码:

from twill.commands import *
from twill import get_browser

go("https://trakcarelabwebview.nhls.ac.za/trakcarelab/csp/logon.csp")
showforms()

fv("1", "USERNAME", "xx")
fv("1", "PASSWORD", "xx")
fv("1", "Logon", "Logon")

formaction('Logon','https://trakcarelabwebview.nhls.ac.za/trakcarelab/csp/logon.csp#TRAK_main')
submit()
show()
showforms()

Where the frame "TRAK_main" is the frame with the HTML I need. 框架“ TRAK_main”是我需要的HTML框架。 The last showforms() shows exactly the same forms as before the "login". 最后一个showforms()显示与“登录”之前完全相同的形式。

What am I doing wrong here? 我在这里做错了什么?

What am I doing wrong here? 我在这里做错了什么?

Your answer lies here: 您的答案就在这里:

twill does not understand javascript. 斜纹不懂javascript。

When a browser loads that page, the js on the page executes, and the js assigns an onclick event handler to the Logon button. browser加载该页面时,页面上的js将执行,并且js将onclick事件处理程序分配给“登录”按钮。 Then when the Logon button is clicked the event handler function sets the value for one of the hidden form fields. 然后,单击“登录”按钮时,事件处理程序功能将为隐藏的表单字段之一设置值。 The server checks for that value in the request, and if the value is absent the login fails, and the server redirects back to the login page. 服务器在请求中检查该值,如果不存在该值,则登录失败,并且服务器重定向回到登录页面。

Because twill does not understand js, the value for the hidden form field never gets set, and therefore when twill sends a request to the server the value for the hidden form field is missing in the request. 由于twill无法理解js,因此将不会设置隐藏表单字段的值,因此,当twill向服务器发送请求时,请求中将缺少隐藏表单字段的值。

Websites try all kinds of tricks to keep programs from accessing their pages. 网站尝试各种技巧来阻止程序访问其页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM