机械化br.click_link()和br.follow_link()之间的差异 [英] Mechanize difference between br.click_link() and br.follow_link()
问题描述
我正在使用机械化来自动执行某些表单提交.
要执行此操作,我需要转到某个网站的主页,单击带有特定文本的链接,该链接会将我重定向到另一个页面,然后在新页面中填写表格.
我尝试使用
response = br.follow_link(text_regex="sometext")
for f in response.forms()
print f.name
我收到的错误消息是AttributeError:closeable_response实例没有属性'forms'
当我尝试
for f in br.forms()
print f.name
它在主页中打印表单名称,而不是我重定向到的新页面.
如何在新页面中找到表单的名称?
响应"包含什么?
click_link()和follow_link()有什么区别?机械化文档没有对此做出清楚的解释.
谢谢
有关click_link()和follow_link()之间的区别:
两种方法都使用与参数相同的关键字.-
click_link()是一种将返回Request对象的方法,然后该对象可用于创建请求:
req = br.click_link(text='Sample Text') br.open(req)
-
follow_link()将执行与.open()相同的操作,直接打开链接.
Follow_link()行为可以在wwwsearch给出的示例中观察到: http://wwwsearch.sourceforge.net/mechanize/
I am using mechanize to automate some form submissions.
To do that I require to go to the home page of some website, click on a link with a particular text which redirects me to an another page and fill in the form in the new page.
I tried using
response = br.follow_link(text_regex="sometext")
for f in response.forms()
print f.name
The error Message I got was AttributeError: closeable_response instance has no attribute 'forms'
When I tried
for f in br.forms()
print f.name
It prints the name of forms in the hompage and not the new page I redirect to .
How can find the name of the forms in the new page ?
What does 'response' contain ?
And what is the difference between click_link() and follow_link() . The mechnanize doc doesn't explain this clearly.
Thanks
for the difference between click_link() and follow_link():
both methods take the same keywords as parameters.
click_link() is a method which will return a Request object, which then can be used for creating a request:
req = br.click_link(text='Sample Text') br.open(req)
follow_link() will perform the same action as .open(), directly opening the link.
This information has been taken from the following documentation: http://joesourcecode.com/Documentation/mechanize0.2.5/mechanize._mechanize.Browser-class.html#click_link
Follow_link() behaviour can be observed in the examples given at wwwsearch: http://wwwsearch.sourceforge.net/mechanize/
这篇关于机械化br.click_link()和br.follow_link()之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!