mechanize-python

Are cookies kept in a Mechanize browser between opening URLs?

放肆的年华 提交于 2020-01-16 01:20:29
问题 I have code similar to this: br = mechanize.Browser() br.open("https://mysite.com/") br.select_form(nr=0) #do stuff here response = br.submit() html = response.read() #now that i have the login cookie i can do this... br.open("https://mysite.com/") html = response.read() However, my script is responding like it's not logged in for the second request. I checked the first request and yes, it logs in successfully. My question is: do cookies in Mechanize browsers need to be managed or do I need

Handling exceptions from urllib2 and mechanize in Python

余生颓废 提交于 2020-01-01 07:20:56
问题 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

what does mechanize tag br.set_handle_gzip do?

回眸只為那壹抹淺笑 提交于 2019-12-31 03:48:04
问题 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

Python Mechanize + GAEpython code

南楼画角 提交于 2019-12-28 11:57:07
问题 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, throwing File “D:\data\eclipse-php\testpy4\src\mechanize\_http.py”, line 43, in socket._fileobject(”fake socket”, close=True) File “C:\Program Files (x86)\Google\google_appengine\google\appengine\dist\socket.py”, line 42, in _fileobject fp.fileno = lambda

scraping way2sms with mechanize

无人久伴 提交于 2019-12-25 01:54:01
问题 I am trying to send an sms with by scraping way2sms.com, but I am unable to login into way2sms.com using mechanize. I am using following code to submit the login form. import mechanize br = mechanize.Browser() br.set_handle_robots(False) br.set_handle_refresh(False) br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0')] res=br.open('http://wwwa.way2sms.com/content/prehome.jsp') link=list(br.links())[5] res=br.follow_link(link) br.form = list

Can't print a specific line from text file

匆匆过客 提交于 2019-12-24 13:42:54
问题 So I currently have this code to read an accounts.txt file that looks like this: username1:password1 username2:password2 username3:password3 I then have this (thanks to a member here) read the accounts.txt file and split it at the username and password so I can later print it. When I try to print line 1 with the username and password separate with this code: with open('accounts.txt') as f: credentials = [x.strip().split(':') for x in f.readlines()] for username,password in credentials: print

Forcing Mechanize to use SSLv3

佐手、 提交于 2019-12-23 16:32:14
问题 How would you force mechanize to use SSLv3 for HTTPS URLs that require it? If I try to use mechanize with all SSLv3-only URLs, I get the error: URLError: <urlopen error [Errno 1] _ssl.c:504: error:140773E8:SSL routines:SSL23_GET_SERVER_HELLO:reason(1000)> 回答1: A dirty answer... not requiring patching. import ssl from ssl import PROTOCOL_SSLv23, PROTOCOL_SSLv3, CERT_NONE, SSLSocket def monkey_wrap_socket(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version

Changing the link in python mechanize

给你一囗甜甜゛ 提交于 2019-12-23 03:56:36
问题 I am trying to write a python script that will generate the rank-list of my batch. For this I simply need to change the roll-number parameter of the link using inspect element feature in web-browser. The link(relative) looks something like: /academic/utility/AcademicRecord.jsp?loginCode=000&loginnumber=000&loginName=name&Home=ascwebsite I just need to change the loginCode to get the grade of my batch-mates. I am trying to use python to iterate through all the roll-numbers and generate a rank

python: module has no attribute mechanize

你离开我真会死。 提交于 2019-12-22 11:13:05
问题 #!/usr/bin/env python import mechanize mech = mechanize.Browser() page = br.open(SchoolRank('KY')) Gives: Traceback (most recent call last): File "mechanize.py", line 2, in <module> import mechanize File "/home/jcress/Documents/programming/schooldig/trunk/mechanize.py", line 12, in <module> mech = mechanize.Browser() AttributeError: 'module' object has no attribute 'Browser' And I'm confused. I have the module installed for 2.6 and 2.7, same result... 回答1: Change your filename away from

Mechanize in Python - Redirect is not working after submit

十年热恋 提交于 2019-12-22 08:24:04
问题 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