mechanize

Python and mechanize login script

安稳与你 提交于 2019-12-05 22:10:52
问题 Hi fellow programmers! I am trying to write a script to login into my universities "food balance" page using python and the mechanize module... This is the page I am trying to log into: http://www.wcu.edu/11407.asp The website has the following form to login: <FORM method=post action=https://itapp.wcu.edu/BanAuthRedirector/Default.aspx><INPUT value=https://cf.wcu.edu/busafrs/catcard/idsearch.cfm type=hidden name=wcuirs_uri> <P><B>WCU ID Number<BR></B><INPUT maxLength=12 size=12 type=password

How to set the Referer header before loading a page with Ruby mechanize?

半世苍凉 提交于 2019-12-05 19:40:18
Is there a straightforward way to set custom headers with Mechanize 2.3? I tried a former solution but get: $agent = Mechanize.new $agent.pre_connect_hooks << lambda { |p| p[:request]['Referer'] = 'https://wwws.mysite.com/cgi-bin/apps/Main' } # ./mech.rb:30:in `<main>': undefined method `pre_connect_hooks' for nil:NilClass (NoMethodError) The docs say: get(uri, parameters = [], referer = nil, headers = {}) { |page| ... } so for example: agent.get 'http://www.google.com/', [], agent.page.uri, {'foo' => 'bar'} alternatively you might like: agent.request_headers = {'foo' => 'bar'} agent.get url

Use python mechanize to log into pages with NTLM authentication

自作多情 提交于 2019-12-05 16:58:41
I want to use mechanize to log into a page and retrieve some information. But however I try to authenticate It just fails with Error code HTTP 401 , as you can see below: r = br.open('http://intra') File "bui...e\_mechanize.py", line 203, in open File "bui...g\mechanize\_mechanize.py", line 255, in _mech_openmechanize._response.httperror_seek_wrapper: HTTP Error 401: Unauthorized This is my code so far: import mechanize import cookielib # Browser br = mechanize.Browser() # Cookie Jar cj = cookielib.LWPCookieJar() br.set_cookiejar(cj) # Browser options br.set_handle_equiv(True) # br.set_handle

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

How to get Mechanize to auto-convert body to UTF8?

余生长醉 提交于 2019-12-05 12:17:58
I found some solutions using post_connect_hook and pre_connect_hook , but it seems like they don't work. I'm using the latest Mechanize version (2.1). There are no [:response] fields in the new version, and I don't know where to get them in the new version. https://gist.github.com/search?q=pre_connect_hooks https://gist.github.com/search?q=post_connect_hooks Is it possible to make Mechanize return a UTF8 encoded version, instead of having to convert it manually using iconv ? nagoya0 Since Mechanize 2.0, arguments of pre_connect_hooks() and post_connect_hooks() were changed. See the Mechanize

Is there a tool like mechanize for Android? [closed]

雨燕双飞 提交于 2019-12-05 11:43:43
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I'm creating an Android app which must do some web surfing in the background in order to provide a service to the user. The site I must connect to has no API, it only provides standard HTTP access, with extensive cookie usage but (luckily for me) not much Javascript code. I wonder if there is a library which behaves like python mechanize for Android, or if it's possible to use mechanize itself in the Android app

How do I manually add more cookies to a session which already has cookies set in mechanize?

北战南征 提交于 2019-12-05 10:58:30
I have a python script which scrapes a page and receives a cookie. I want to append another cookie to the existing cookies that are being send to the server. So that on the next request I have the cookies from the original page plus ones I set manually. Anyway of doing this? I tried addheaders in mechanize but it was ignored. Use the set_cookie method: >>> import mechanize >>> br=mechanize.Browser() >>> br.set_cookie? Definition: br.set_cookie(self, cookie_string) Docstring: Request to set a cookie. Note that it is NOT necessary to call this method under ordinary circumstances: cookie handling

How do I configure a Ruby Mechanize agent to work through the Charles web proxy?

我的未来我决定 提交于 2019-12-05 10:31:16
I'm writing an "automatically fill in the forms" app using Ruby / Mechanize. It almost works. I can use the wonderful Charles web proxy to see the exchange between the server and my Firefox browser. Now I want to use Charles to see the exchange between the server and my app. Charles proxies on port 8888. Assume that the server is at https://my.host.com . One thing that does NOT work is: @agent ||= Mechanize.new do |agent| agent.set_proxy("my.host.com", 8888) end This results in a Net::HTTP::Persistent::Error : ...lib/net/http/persistent.rb:579:in `rescue in connection_for': connection refused:

Mechanize - How to follow or “click” Meta refreshes in rails

断了今生、忘了曾经 提交于 2019-12-05 10:16:19
I have a bit trouble with Mechanize. When a submit a form with Mechanize. I am come to a page with one meta refresh and there is no links. My question is how do i follow the meta refresh? I have tried to allow meta refresh but then i get a socket error. Sample code require 'mechanize' agent = WWW::Mechanize.new agent.get("http://euroads.dk") form = agent.page.forms.first form.username = "username" form.password = "password" form.submit page = agent.get("http://www.euroads.dk/system/index.php?showpage=login") agent.page.body The response: <html> <head> <META HTTP-EQUIV=\"Refresh\" CONTENT=\"0

Mechanze form submission causes 'Assertion Error' in response when .read() is attempted

一笑奈何 提交于 2019-12-05 07:01:09
问题 I am writing a web-crawl program with python and am unable to login using mechanize. The form on the site looks like: <form method="post" action="PATLogon"> <h2 align="center"><img src="/myaladin/images/aladin_logo_rd.gif"></h2> <!-- ALADIN Request parameters --> <input type=hidden name=req value="db"> <input type=hidden name=key value="PROXYAUTH"> <input type=hidden name=url value="http://eebo.chadwyck.com/search"> <input type=hidden name=lib value="8"> <table> <tr><td><b>Last Name:</b></td>