Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. Python 2.7.10 (default, Aug  4 2015, 15:36:58)
  2. [GCC 4.2.1 20070831 patched [FreeBSD]] on freebsd9
  3. Type "help", "copyright", "credits" or "license" for more information.
  4.  
  5. >>> import mechanize
  6. >>> import cookielib
  7. >>> br = mechanize.Browser()
  8. >>> cj = cookielib.LWPCookieJar()
  9. >>> br.set_cookiejar(cj)
  10. >>> br.set_handle_equiv(True)
  11. >>> br.set_handle_redirect(True)
  12. >>> br.set_handle_referer(True)
  13. >>> br.set_handle_robots(False)
  14. >>> br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
  15. >>> br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
  16. >>> r = br.open('http://192.168.1.1/restart.lp?tid=RESTART')
  17. >>> html = r.read()
  18. >>> print html
  19.  
  20. Output snippet:
  21. <form name='Restart'  method='post' action='/rebooting.lp'>
  22.     <input type="hidden" name="rn" value="1750705504">
  23.     <input type='hidden' name='restart' value='1'>
  24.     <input type='hidden' name='reboot_action' value='reboot'>
  25.  
  26.     <input type='button' name='18' value='Yes, restart my MediaAccess Gateway'      onClick='submitForm(document.Restart,0,0,"","",0,"")' >
  27.     <input type='button' name='20' value='No' onClick='GoAndRemember("/cgi/b/info/","")' >
  28. </form>
  29.  
  30. Submitting the "Yes"-button errors:
  31. >>> br.submit(name='18')
  32. Traceback (most recent call last):
  33.   File "<stdin>", line 1, in <module>
  34.   File "mechanize/_mechanize.py", line 541, in submit
  35.     return self.open(self.click(*args, **kwds))
  36.   File "mechanize/_mechanize.py", line 530, in click
  37.     request = self.form.click(*args, **kwds)
  38.   File "mechanize/_form.py", line 2999, in click
  39.     self._request_class)
  40.   File "mechanize/_form.py", line 3192, in _click
  41.     name, type, "clickable", id, label, None, nr)
  42.   File "mechanize/_form.py", line 3185, in _find_control
  43.     raise ControlNotFoundError("no control matching "+description)
  44. mechanize._form.ControlNotFoundError: no control matching name '18', kind 'clickable'
  45.  
  46. >>> br.button(name='18')
  47. Traceback (most recent call last):
  48.   File "<stdin>", line 1, in <module>
  49.   File "mechanize/_mechanize.py", line 629, in __getattr__
  50.     return getattr(form, name)
  51.   File "mechanize/_form.py", line 2682, in __getattr__
  52.     return getattr(HTMLForm, name)
  53. AttributeError: class HTMLForm has no attribute 'button'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement