问题
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
回答1:
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/
来源:https://stackoverflow.com/questions/13204781/mechanize-difference-between-br-click-link-and-br-follow-link