471,325 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

basic mechanize help

I'm trying to learn the basics of the mechanize module and i'm very very new to programming.
Does anyone know of some good places to learn the very basics, say with some examples as well?

I found this off of a person's blog
Expand|Select|Wrap|Line Numbers
  1. import re
  2. from mechanize import Browser
  3.  
  4. username = "yourusername"
  5. password = "yourpassword"
  6.  
  7. browser = Browser()
  8. url = "http://www.deviantrealms.com/index.php?act=Login&CODE=00"
  9. browser.open(url)
  10. browser.select_form('LOGIN')
  11. browser['UserName'] = username
  12. browser['PassWord'] = password
  13. response = browser.submit()
  14. response = browser.follow_link(url_regex=r"\s*Top200-L2.php")
  15. browser.back()
  16. response = browser.follow_link(url_regex=r"\s*Top100-L2.php")
This looks like what i think I want to do. that is sign into a web site.

However, does the site need to be set up such that 'LOGIN' is specified just like that in the source code?

when i tried it i get this error:
>>> browser.select_form('LOGIN')
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python25\lib\site-packages\mechanize\_mechanize.py", line 510, in select_form
raise FormNotFoundError("no form matching "+description)
FormNotFoundError: no form matching name 'LOGIN'

thanks
Sep 13 '07 #1
2 3710
bartonc
6,596 Expert 4TB
That's usually due to your URL. If you can browse there in your web browser and get to that form, then it should work.


The Mechanize Readme refers to some tutorials.
Sep 13 '07 #2
Silgd1
25
I'm trying to learn the basics of the mechanize module and i'm very very new to programming.
Does anyone know of some good places to learn the very basics, say with some examples as well?

I found this off of a person's blog
Expand|Select|Wrap|Line Numbers
  1. import re
  2. from mechanize import Browser
  3.  
  4. username = "yourusername"
  5. password = "yourpassword"
  6.  
  7. browser = Browser()
  8. url = "http://www.deviantrealms.com/index.php?act=Login&CODE=00"
  9. browser.open(url)
  10. browser.select_form('LOGIN')
  11. browser['UserName'] = username
  12. browser['PassWord'] = password
  13. response = browser.submit()
  14. response = browser.follow_link(url_regex=r"\s*Top200-L2.php")
  15. browser.back()
  16. response = browser.follow_link(url_regex=r"\s*Top100-L2.php")
This looks like what i think I want to do. that is sign into a web site.

However, does the site need to be set up such that 'LOGIN' is specified just like that in the source code?

when i tried it i get this error:
>>> browser.select_form('LOGIN')
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python25\lib\site-packages\mechanize\_mechanize.py", line 510, in select_form
raise FormNotFoundError("no form matching "+description)
FormNotFoundError: no form matching name 'LOGIN'

thanks

[Silgd1] View the source code of the site and make sure that the name of the form is 'LOGIN'. From the error you are receiving, it look likes the name of the form is not 'LOGIN'. View the source code of the site again and double check the name of the form. You'll be looking for something like this <FORM name=fileupload action='/emkt/xml/submit' method=post
encType=multipart/form-data target="_top">...this tells you the name of the form is "fileupload". Look for something similar to this - Silgd1[/Silgd1]
Jan 22 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by zoewu | last post: by
6 posts views Thread by sureshbup | last post: by
1 post views Thread by Neal Becker | last post: by
2 posts views Thread by Rex | last post: by
1 post views Thread by tedpottel | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.