mechanize

Python mechanize with NTLM getting AttributeError: HTTPResponse instance has no attribute '__iter__'

こ雲淡風輕ζ 提交于 2019-12-01 07:40:41
问题 I am trying to access a site that's secured with NTLM authentication using python-ntlm and mechanize but I am getting this error. File "build/bdist.macosx-10.6-universal/egg/mechanize/_mechanize.py", line 203, in open File "build/bdist.macosx-10.6-universal/egg/mechanize/_mechanize.py", line 249, in _mech_open File "build/bdist.macosx-10.6-universal/egg/mechanize/_mechanize.py", line 304, in _set_response File "build/bdist.macosx-10.6-universal/egg/mechanize/_response.py", line 521, in

Send binary image by POST request

∥☆過路亽.° 提交于 2019-12-01 07:24:18
问题 i am trying to do a post request to upload a img to https://pasteboard.co/, but i am always getting a 500 response which tells me, there is a missing file. The file is really existing and the path is correct, i don't know where the problem is. import mechanicalsoup browser = mechanicalsoup.StatefulBrowser() browser.set_user_agent( 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36') response = browser.open('https:/

Python Mechanize - how to add a header on a single .open() call?

瘦欲@ 提交于 2019-12-01 06:42:33
I'm trying to get around a certain service not having an API and decided to try Mechanize (I normally use urllib). How do I add a specific header for one open call? Or is there a way to construct a Request instance with its own headers, then have my mechanize.Browser instance handle it? browser = mechanize.Browser() headers = [ ('Accept', 'text/javascript, text/html, application/xml, text/xml, */*'), ('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8'), ('User-Agent', 'Foobar'), ] browser.addheaders = headers # log in, do stuff, etc. # here, for this one browser request, I need

Mechanize does not see some hidden form inputs?

一世执手 提交于 2019-12-01 06:42:11
I want to scrape this web page using Mechanize. The form element looks like this: <form name="ctl00" method="post" action="PSearchResults.aspx?state=ME&rp=" id="ctl00"> <div> <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="verylongstring" /> </div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKb7POZAwK4v7ffCOmari00yJft/iuZBMdOH/zh9TDI" /> </div> </form> I'm using Mechanize to print out the

Selecting an unnamed text field in a mechanize form (python)

早过忘川 提交于 2019-12-01 06:28:06
问题 So i'm making a program to batch convert street addresses to gps co-ordinates using mechanize and python. this is my first time using mechanize. I can select the form ("form2') on the page. however the text box in the form has no name. how do i select the textbox so that mechanize can enter my text? I've tried selecting it by its id. but that does not work. br.select_form("Form2") #works as far as i know br.form["search"] = ["1 lakewood drive, christchurch"] #this is the field that i cannot

Python Mechanize - how to add a header on a single .open() call?

寵の児 提交于 2019-12-01 05:34:37
问题 I'm trying to get around a certain service not having an API and decided to try Mechanize (I normally use urllib). How do I add a specific header for one open call? Or is there a way to construct a Request instance with its own headers, then have my mechanize.Browser instance handle it? browser = mechanize.Browser() headers = [ ('Accept', 'text/javascript, text/html, application/xml, text/xml, */*'), ('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8'), ('User-Agent', 'Foobar'

Mechanize does not see some hidden form inputs?

丶灬走出姿态 提交于 2019-12-01 04:44:13
问题 I want to scrape this web page using Mechanize. The form element looks like this: <form name="ctl00" method="post" action="PSearchResults.aspx?state=ME&rp=" id="ctl00"> <div> <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="verylongstring" /> </div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="

Encoding problem downloading HTML using mechanize and Python 2.6

时间秒杀一切 提交于 2019-12-01 04:26:06
问题 browser = mechanize.Browser() page = browser.open(url) html = page.get_data() print html It shows some strange characters. I suppose that it is UTF-8 string but Python doesn't know that and cannot show it properly. How can I convert this string to unicode string like u = u'test' 回答1: It was gzipped def ungzipResponse(r,b): headers = r.info() if headers['Content-Encoding']=='gzip': import gzip gz = gzip.GzipFile(fileobj=r, mode='rb') html = gz.read() gz.close() headers["Content-type"] = "text

Rails 3 - Log into another site and keep cookie in session

不问归期 提交于 2019-12-01 04:11:31
问题 I'm putting together a small app which will allow a user to log into a semi-popular social networking site that doesn't have a sufficient API, so I'm using the mechanize gem to automate a few functions I wanted to add for anyone to use, such as bulk messaging. Because of the API restrictions, I'm forced to do this by pretending to be a user interacting with the http interface of the site. The problem I'm having is once a user logs in to my site, how can I keep the cookie from the social

Using Ruby and Mechanize to fill in a remote login form mystery

馋奶兔 提交于 2019-11-30 23:11:25
I am trying to implement a Ruby script that will take in a username and password, then proceed to fill in the account details on a login form on another website and return the then follow a link and retrieve the account history. To do this I am using the Mechanize gem. I have been following the examples here but still I cant seem to get it to work. I have simplified this down greatly to try get it to work in parts but a supposedly simple filling in a form is holding me up. Here is my code: # script gets called with a username and password for the site require 'mechanize' #create a mechanize