mechanize-python

python mechanize forms() err

情到浓时终转凉″ 提交于 2019-12-07 22:29:40
问题 I'm using Python 2.7.6 and mechanize 0.2.5 and I want to log in to 'dining.ut.ac.ir' (I have the username and password)- but when I try to run the below script to get the forms list : import mechanize br = mechanize.Browser() br.set_handle_robots(False) br.addheaders = [('User-agent', 'Firefox')] br.open("http://dining.ut.ac.ir/") br.forms() I get this error: Traceback (most recent call last): File "script.py", line 8, in <module> br.forms() File "/home/arman/workspace/python/mechanize/venv

mechanize open Url python

☆樱花仙子☆ 提交于 2019-12-07 14:08:51
问题 I am trying to open a URL using mechanize in python. The code executes with no errors, but nothing actually happens. What am I missing? Also, is there a way to set the browser? This is python 2.7. import mechanize url='http://www.google.com/' op = mechanize.Browser() # use mecahnize's browser op.set_handle_robots(False) #tell the webpage you're not a robot op.open(url) 回答1: mechanize doesn't use real browsers - it is a tool for programmatic web-browsing. For example, print out the page title

Mechanizer in python - selecting form field with no name

走远了吗. 提交于 2019-12-07 12:59:47
问题 I have a problem similar to Selecting an unnamed text field in a mechanize form (python) and Use mechanize to submit form without control name . I want to scrape the data of a website behind a login screen. However, I don't know how to select a form field that does not have a name. The controls look like this: <TextControl(<None>=)> <PasswordControl(<None>=)> <CheckboxControl(<None>=[on])> <SubmitButtonControl(<None>=) (readonly)>> Usually it says <TextControl(login=)> , so I can use br.form[

python mechanize forms() err

亡梦爱人 提交于 2019-12-06 13:16:49
I'm using Python 2.7.6 and mechanize 0.2.5 and I want to log in to 'dining.ut.ac.ir' (I have the username and password)- but when I try to run the below script to get the forms list : import mechanize br = mechanize.Browser() br.set_handle_robots(False) br.addheaders = [('User-agent', 'Firefox')] br.open("http://dining.ut.ac.ir/") br.forms() I get this error: Traceback (most recent call last): File "script.py", line 8, in <module> br.forms() File "/home/arman/workspace/python/mechanize/venv/lib/python2.7/site-packages/mechanize/_mechanize.py", line 420, in forms return self._factory.forms()

Python mechanize form submitting doesn't work

删除回忆录丶 提交于 2019-12-06 11:59:12
I am trying to write a simple bot that would login to my account on a page and then comment other users' images. However I am not able to get the comment form submitting work correctly. The comment form looks like this: <form id="comment-form" action="#" onsubmit="postComment($(this).serialize(),'image',117885,229227); return false;"> <input class="comment" type="text" size="40" name="comment" id="comment" /> <input type="hidden" name="commentObj" value="9234785" /> <input type="hidden" name="commentMode" value="image" /> <input type="hidden" name="userid" value="12427" /> <input class="submit

Web Scraper: Limit to Requests Per Minute/Hour on Single Domain?

送分小仙女□ 提交于 2019-12-06 08:38:12
问题 I'm working with a librarian to re-structure his organization's digital photography archive. I've built a Python robot with Mechanize and BeautifulSoup to pull about 7000 poorly structured and mildy incorrect/incomplete documents from a collection. The data will be formatted for a spreadsheet he can use to correct it. Right now I'm guesstimating 7500 HTTP requests total to build the search dictionary and then harvest the data, not counting mistakes and do-overs in my code, and then many more

Verifying br.submit() using Python's Mechanize module

爷,独闯天下 提交于 2019-12-06 05:28:59
Just trying to login to a website using mechanize. When I print "br.form", I can see my credentials entered into my form. But I do not know how to actually submit the form properly. I use "br.submit()" and attempt to verify it has proceeded to the next page by printing the br.title(), but the title appearing is for the login screen, and not the post-login screen. import mechanize from time import sleep def reportDownload(): # Prompt for login credentials print("We require your credentials.") Username = raw_input("Please enter your username. ") Password = raw_input("Please input your password.

python: module has no attribute mechanize

拈花ヽ惹草 提交于 2019-12-06 02:59:43
#!/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... Change your filename away from mechanize.py. Python is importing your file as the module. 来源: https://stackoverflow.com/questions/4236365/python

mechanize open Url python

你。 提交于 2019-12-05 23:43:56
I am trying to open a URL using mechanize in python. The code executes with no errors, but nothing actually happens. What am I missing? Also, is there a way to set the browser? This is python 2.7. import mechanize url='http://www.google.com/' op = mechanize.Browser() # use mecahnize's browser op.set_handle_robots(False) #tell the webpage you're not a robot op.open(url) mechanize doesn't use real browsers - it is a tool for programmatic web-browsing. For example, print out the page title after opening the url: >>> import mechanize >>> url='http://www.google.com/' >>> op = mechanize.Browser() >>

Mechanizer in python - selecting form field with no name

て烟熏妆下的殇ゞ 提交于 2019-12-05 22:28:54
I have a problem similar to Selecting an unnamed text field in a mechanize form (python) and Use mechanize to submit form without control name . I want to scrape the data of a website behind a login screen. However, I don't know how to select a form field that does not have a name. The controls look like this: <TextControl(<None>=)> <PasswordControl(<None>=)> <CheckboxControl(<None>=[on])> <SubmitButtonControl(<None>=) (readonly)>> Usually it says <TextControl(login=)> , so I can use br.form['login'] = 'mylogin' But this time I can't, since I don't know the name of the login field. I'm able to