mechanize-python

Mechanize in Python - Redirect is not working after submit

元气小坏坏 提交于 2019-12-05 12:55:36
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 think I don't know how to look for that documentation since all I can find is code examples which don't really teach me how to do the particular things I'm trying to do. If anyone could point me to such documentation, I'd be glad to read it myself and solve my problem. For the actual problem, I'm trying to log in to a website by sending my username and

Requests, Mechanize, urllib fails but cURL works

限于喜欢 提交于 2019-12-04 14:44:22
问题 Whilst attempting to access this site through requests, I receive: ('Connection aborted.', error(54, 'Connection reset by peer')) I have also tried to access the site through mechanize and urllib, both failed. However cURL works fine (see end for code). I have tried requests.get() with combinations of parameters verify=True , stream=True and I have also tried a request with the cURL header. I tried to move to urllib / Mechanize as alternatives but both gave the same error. My code for

Handling exceptions from urllib2 and mechanize in Python

ぃ、小莉子 提交于 2019-12-03 21:27:08
I am a novice at using exception handling. I am using the mechanize module to scrape several websites. My program fails frequently because the connection is slow and because the requests timeout. I would like to be able to retry the website (on a timeout, for instance) up to 5 times after 30 second delays between each try. I looked at this stackoverflow answer and can see how I can handle various exceptions. I also see (although it looks very clumsy) how I can put the try/exception inside a while loop to control the 5 attempts ... but I do not understand how to break out of the loop, or

Python Mechanize select form FormNotFoundError

强颜欢笑 提交于 2019-12-03 12:48:40
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: <form id="login_form" onsubmit="return Index.login_submit();" method="post" action="index.php?action=login&server_list=1"> But I'm getting this Error: mechanize._mechanize.FormNotFoundError: no form matching name 'login_form The problem is that your form does not have a name, only an id, and it is login_form . You can use a predicate: br.select_form(predicate=lambda f: f.attrs.get('id', None) == 'login_form') (where you se if f.attrs has the key

CertificateError: hostname doesn't match

点点圈 提交于 2019-12-03 11:36:21
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 gotten past all of the login, password, security questioon screens, but it is getting hung up on the certification. Any help would be amazing. I've tried the monkeywrench found here: Forcing Mechanize to use SSLv3 Doesn't work for my code though. If you want the code file I'd be happy to send. You can avoid this error by monkey patching ssl: import ssl

Requests, Mechanize, urllib fails but cURL works

醉酒当歌 提交于 2019-12-03 09:12:31
Whilst attempting to access this site through requests, I receive: ('Connection aborted.', error(54, 'Connection reset by peer')) I have also tried to access the site through mechanize and urllib, both failed. However cURL works fine (see end for code). I have tried requests.get() with combinations of parameters verify=True , stream=True and I have also tried a request with the cURL header. I tried to move to urllib / Mechanize as alternatives but both gave the same error. My code for requests is as follows: import requests import cookielib url = "https://datamuster.marketdatasuite.com/Account

Python mechanize javascript

主宰稳场 提交于 2019-12-02 04:47:48
问题 I'm trying to use mechanize to grab prices for New York's metro-north railroad from this site: http://as0.mta.info/mnr/fares/choosestation.cfm The problem is that when you select the first option, the site uses javascript to populate your list of possible destinations. I have written equivalent code in python, but I can't seem to get it all working. Here's what I have so far: import mechanize import cookielib from bs4 import BeautifulSoup br = mechanize.Browser() br.set_handle_robots(False)

what does mechanize tag br.set_handle_gzip do?

落爺英雄遲暮 提交于 2019-12-02 03:28:51
I'm trying python mechanize module in order to write some scripts. When i run it i get the following error.What actually is this set_handle_gzip ? manoj@ubuntu:~/pyth$ python rock.py │ rock.py:15: UserWarning: gzip transfer encoding is experimental! │ br.set_handle_gzip(True) │ Traceback (most recent call last): │ File "rock.py", line 60, in <module> │ br.follow_link(text='Sign out') │ File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line│ 569, in follow_link │ return self.open(self.click_link(link, **kwds)) │ File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py",

Python mechanize javascript

孤人 提交于 2019-12-02 00:10:10
I'm trying to use mechanize to grab prices for New York's metro-north railroad from this site: http://as0.mta.info/mnr/fares/choosestation.cfm The problem is that when you select the first option, the site uses javascript to populate your list of possible destinations. I have written equivalent code in python, but I can't seem to get it all working. Here's what I have so far: import mechanize import cookielib from bs4 import BeautifulSoup br = mechanize.Browser() br.set_handle_robots(False) br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615

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

我们两清 提交于 2019-11-29 13:58:42
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 all the fields. The form data fetched via mechanize (for f in br.forms() print: f) <POST http://www.example.com/takeupload.php multipart/form-data <HiddenControl(MAX_FILE_SIZE=1000000) (readonly)> <TextControl(<None>=http://www.example.com:81/test.php?pass=550) (readonly)> <FileControl(file=<No files added>)> <TextControl(name=)> <SelectControl(type