Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python 2.7.10 (default, Aug 4 2015, 15:36:58)
- [GCC 4.2.1 20070831 patched [FreeBSD]] on freebsd9
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import mechanize
- >>> import cookielib
- >>> br = mechanize.Browser()
- >>> cj = cookielib.LWPCookieJar()
- >>> br.set_cookiejar(cj)
- >>> br.set_handle_equiv(True)
- >>> br.set_handle_redirect(True)
- >>> br.set_handle_referer(True)
- >>> br.set_handle_robots(False)
- >>> br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
- >>> 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')]
- >>> r = br.open('http://192.168.1.1/restart.lp?tid=RESTART')
- >>> html = r.read()
- >>> print html
- Output snippet:
- <form name='Restart' method='post' action='/rebooting.lp'>
- <input type="hidden" name="rn" value="1750705504">
- <input type='hidden' name='restart' value='1'>
- <input type='hidden' name='reboot_action' value='reboot'>
- <input type='button' name='18' value='Yes, restart my MediaAccess Gateway' onClick='submitForm(document.Restart,0,0,"","",0,"")' >
- <input type='button' name='20' value='No' onClick='GoAndRemember("/cgi/b/info/","")' >
- </form>
- Submitting the "Yes"-button errors:
- >>> br.submit(name='18')
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "mechanize/_mechanize.py", line 541, in submit
- return self.open(self.click(*args, **kwds))
- File "mechanize/_mechanize.py", line 530, in click
- request = self.form.click(*args, **kwds)
- File "mechanize/_form.py", line 2999, in click
- self._request_class)
- File "mechanize/_form.py", line 3192, in _click
- name, type, "clickable", id, label, None, nr)
- File "mechanize/_form.py", line 3185, in _find_control
- raise ControlNotFoundError("no control matching "+description)
- mechanize._form.ControlNotFoundError: no control matching name '18', kind 'clickable'
- >>> br.button(name='18')
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "mechanize/_mechanize.py", line 629, in __getattr__
- return getattr(form, name)
- File "mechanize/_form.py", line 2682, in __getattr__
- return getattr(HTMLForm, name)
- AttributeError: class HTMLForm has no attribute 'button'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement