File: simple.py

package info (click to toggle)
python-mechanize 1%3A0.4.8%2Bpypi-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,612 kB
  • sloc: python: 16,644; makefile: 11
file content (22 lines) | stat: -rwxr-xr-x 566 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3

from __future__ import print_function
import sys

from mechanize import Browser, urljoin, urlopen

if len(sys.argv) == 1:
    uri = "http://wwwsearch.sourceforge.net/"
else:
    uri = sys.argv[1]

br = Browser()
br.open(urljoin(uri, "mechanize/example.html"))
form = next(br.forms())
form = br.forms[0]
print(form)
form["comments"] = "Thanks, Gisle"
# form.click() returns a mechanize.Request object
# (see HTMLForm.click.__doc__ if you want to use only the forms support, and
# not the rest of mechanize)
print(urlopen(form.click()).read())