Questions tagged [mechanize-python]

Stateful programmatic web browsing in Python, after Andy Lester’s Perl module WWW::Mechanize.

Stateful programmatic web browsing in Python, after Andy Lester’s Perl module WWW::Mechanize.

Some of the key features:

  • The browser class mechanize.Browser implements the interface of urllib2.OpenerDirector, so any URL can be opened not just http.
  • Easy HTML form filling.
  • Convenient link parsing and following.
  • Browser history (.back() and .reload() methods).
  • The Referer HTTP header is added properly (optional).
  • Automatic observance of robots.txt (can be disabled if desired).
  • Automatic handling of HTTP-Equiv and Refresh.

python-mechanize was created by John J. Lee. Maintenance was taken over by Kovid Goyal.


HomePage | Documentation | Github | FAQ


235 questions
33
votes
3 answers

How to get filename from Content-Disposition in headers

I am downloading a file with Mechanize and in response headers there is a string: Content-Disposition: attachment; filename=myfilename.txt Is there a quick standard way to get that filename value? What I have in mind now is this: filename =…
Sergei Basharov
  • 51,276
  • 73
  • 200
  • 335
18
votes
3 answers

CertificateError: hostname doesn't match

I'm using a proxy (behind corporate firewall), to login to an https domain. The SSL handshake doesn't seem to be going well: CertificateError: hostname 'ats.finra.org:443' doesn't match 'ats.finra.org' I'm using Python 2.7.9 - Mechanize and I've…
pugmastaflex
  • 470
  • 1
  • 5
  • 17
12
votes
1 answer

Cannot press button

I'm trying to code a bot for a game, and need some help to do it. Being a complete noob, I googled how to do it with python and started reading a bit about mechanize.
11
votes
3 answers

Python: how to dump cookies of a mechanize.Browser instance?

I am learning how to use mechanize, a Python module to automate interacting with websites. One feature is the automated handling of cookies. I would to want to dump cookies from a mechanize.Browser instance for debugging purposes, but I can't seem…
Anonymous
  • 3,011
  • 4
  • 24
  • 23
10
votes
2 answers

Python Mechanize select form FormNotFoundError

I want to select a form with mechanize. This is my code: br = mechanize.Browser() self.br.open(url) br.select_form(name="login_form") The form's code:
jgillich
  • 71,459
  • 6
  • 57
  • 85
10
votes
3 answers

How to get mechanize requests to look like they originate from a real browser

OK, here's the header(just an example) info I got from Live HTTP Header while logging into an account: http://example.com/login.html POST /login.html HTTP/1.1 Host: example.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8)…
Shane
  • 4,875
  • 12
  • 49
  • 87
8
votes
1 answer

Submitting a form with mechanize (TypeError: ListControl, must set a sequence)

I'm trying to submit a form with mechanize but have run into an error (TypeError: ListControl, must set a sequence) After googling for some time and trying a couple of different solutions I haven't been able to solve the issue. I'm trying to submit…
Michael Esteves
  • 1,445
  • 3
  • 21
  • 38
7
votes
2 answers

Mechanize and Python, clicking href="javascript:void(0);" links and getting the response back

I need to scrap some data from page, where I fill out the form (already did this with mechanize). The problem is, the page returns data on many pages, and I have troubles from getting the data from those pages. There's no problem to get them from…
yak
  • 3,770
  • 19
  • 60
  • 111
7
votes
2 answers

Sending a POST with mechanize and requests.

I am trying to send a POST using mechanize however my code won't work sometimes(and I know why). I have used mechanize, twill and requests. With mechanize and twills it is working and with requests it is not. Probably I am doing it in wrong way.…
avi
  • 9,292
  • 11
  • 47
  • 84
6
votes
5 answers

Mechanize: too many values to unpack (expected 2)

I have tried to write the following code, I am trying to write a code in Python 3.7 that just opens a web browser and the website fed to it in the Command Line: Example.py import sys from mechanize import Browser browser =…
Code_Ninja
  • 1,729
  • 1
  • 14
  • 38
6
votes
5 answers

how to set cookie in python mechanize

After sending request to the server br.open('http://xxxx') br.select_form(nr=0) br.form['MESSAGE'] = '1 2 3 4 5' br.submit() I get the response title, which has set-cookie Set-Cookie: PON=xxx.xxx.xxx.111; expires=Tue, 17-Mar-2015…
John
  • 3,888
  • 11
  • 46
  • 84
5
votes
1 answer

How to fill and submit a form using python

I am filling a form of a web page with the help of mechanize module but I am getting error when I run my code. I just want to fill the form and submit it successfully. My attempt : code snippet from this stack answer import re from mechanize import…
5
votes
2 answers

Twill/Mechanize access to html content

Couple of questions regarding Twill and Mechanize: Is Twill still relevant as a web-automation tool? If yes, then why is not currently maintained? If no, has Mechanize matured further to support Twill-style simple scripting? Or is there another…
Shaheeb Roshan
  • 611
  • 1
  • 7
  • 17
5
votes
3 answers

Python Mechanize + GAEpython code

I am aware of previous questions regarding mechanize + Google App Engine, What pure Python library should I use to scrape a website? and Mechanize and Google App Engine. Also there is some code here, which I cannot get to work on app engine,…
Lydon Ch
  • 8,637
  • 20
  • 79
  • 132
5
votes
1 answer

Mechanize in Python - Redirect is not working after submit

I just started using mechanize in Python and I'm having some problems with it already. I've looked around on StackOverflow and on Google and I've seen people say that the documentation is great and that it should be easy to get it working, but I…
Jumbala
  • 4,764
  • 9
  • 45
  • 65
1
2 3
15 16