mechanize

Python mechanize - two buttons of type 'submit'

拥有回忆 提交于 2019-12-03 06:40:20
问题 I have a mechanize script written in python that fills out a web form and is supposed to click on the 'create' button. But there's a problem, the form has two buttons. One for 'add attached file' and one for 'create'. Both are of type 'submit', and the attach button is the first one listed. So when I select the forum and do br.submit(), it clicks on the 'attach' button instead of 'create'. Extensive Googling has yielded nothing useful for selecting a specific button in a form. Does anyone

Recovering from HTTPError in Mechanize

你说的曾经没有我的故事 提交于 2019-12-03 06:38:53
I am writing a function for some existing python code that will be passed a Mechanize browser object as a parameter. I fill in some details in a form in the browser, and use response = browser.submit() to move the browser to a new page, and collect some information from it. Unfortunately, I occasionally get the following error: httperror_seek_wrapper: HTTP Error 500: Internal Server Error I've navigated to the page in my own browser, and sure enough, I occasionally see this error directly, so I think this is a server problem, not anything to do with robots.txt , headers or similar. The problem

How do you select choices in a form using Python?

元气小坏坏 提交于 2019-12-03 06:13:42
问题 I'd like to know how to select options in a form that is formatted like <td align="left"> <select name="FORM1" id="FORM1" multiple="multiple" size="5"> <option value="Value1">Value1</option> <option value="Value2">Value2</option> </select> </td> Right now, I am using mechanize to connect to the website and traverse to the desired page. This page has many forms such as FORM1, FORM2, FORM3, etc. with options. I'd like to select (enable) Value1 then tell the instance of mechanize to hit the

How to test a ruby application which uses mechanize

风流意气都作罢 提交于 2019-12-03 05:51:23
问题 I wrote a small program that uses Mechanize to traverse a site. I want to write tests for it, but don't want it to actually go log onto the site every time I run the tests. I would like to mock the internet, so that when it goes to some site, it simply returns the stored results. Here is a small example, pretend my code's purpose was to pull links off of the google homepage, so I write a test to ensure the first link my code finds has the text "Images". I might write something like this:

mechanize how to get current url

六月ゝ 毕业季﹏ 提交于 2019-12-03 01:52:07
I have this code require 'mechanize' @agent = Mechanize.new page = @agent.get('http://something.com/?page=1') next_page = page.link_with(:href=>/^?page=2/).click As you can see this code should go to the next page. The next_page should have url http://something.com/?page=2 How to get current url for next_page ? sunnyrjuneja next_page.uri.to_s See http://www.rubydoc.info/gems/mechanize/Mechanize/Page/Link#uri-instance_method and http://ruby-doc.org/stdlib-2.4.1/libdoc/uri/rdoc/URI.html For testing purposes, I did the following in irb: require 'mechanize' @agent = Mechanize.new page = @agent.get

How to get generated captcha image using mechanize

这一生的挚爱 提交于 2019-12-03 01:15:31
I'm trying to use python and mechanize to send sms from my mobile provider website. The problem is that form has a captcha image. Using mechanize I can get the link to the image, but it's different all the time I access that link. Is there any way to get exact picture from mechanize? This is a rough example of how to get the image, note that mechanize uses cookies so any cookies received will be sent to the server with the request for the image (this is probably what you want ). br = mechanize.Browser() response = br.open('http://example.com') soup = BeautifulSoup(response.get_data()) img =

Ruby mechanize post with header

醉酒当歌 提交于 2019-12-03 00:11:29
I have page with js that post data via XMLHttpRequest and server side script check for this header, how to send this header? agent = WWW::Mechanize.new { |a| a.user_agent_alias = 'Mac Safari' a.log = Logger.new('./site.log') } agent.post('http://site.com/board.php', { 'act' => '_get_page', "gid" => 1, 'order' => 0, 'page' => 2 } ) do |page| p page end avout I found this post with a web search (two months later, I know) and just wanted to share another solution. You can add custom headers without monkey patching Mechanize using a pre-connect hook: agent = WWW::Mechanize.new agent.pre_connect

How do I get Python's Mechanize to POST an ajax request?

为君一笑 提交于 2019-12-02 21:21:37
The site I'm trying to spider is using the javascript: request.open("POST", url, true); To pull in extra information over ajax that I need to spider. I've tried various permutations of: r = mechanize.urlopen("https://site.tld/dir/" + url, urllib.urlencode({'none' : 'none'})) to get Mechanize to get the page but it always results in me getting the login HTML again, indicating that something is wrong. Firefox doesn't seem to add any HTTP data to the POST according to Firebug, and I'm adding an empty field to try and force the urlopen to use "POST" instead of "GET" hoping the site ignores the

How do you select choices in a form using Python?

…衆ロ難τιáo~ 提交于 2019-12-02 20:50:38
I'd like to know how to select options in a form that is formatted like <td align="left"> <select name="FORM1" id="FORM1" multiple="multiple" size="5"> <option value="Value1">Value1</option> <option value="Value2">Value2</option> </select> </td> Right now, I am using mechanize to connect to the website and traverse to the desired page. This page has many forms such as FORM1, FORM2, FORM3, etc. with options. I'd like to select (enable) Value1 then tell the instance of mechanize to hit the submit button. Which would be a quick way to enable an option based on the form name? senderle Here are

Are there any alternatives to Mechanize in Python? [closed]

为君一笑 提交于 2019-12-02 20:31:26
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. I'm using Python 3.6 while I have to fill in a form. Unfortunately, mechanize doesn't work on Python 3. What do you suggest as an alternative to mechanize? SeleniumRC with selenium.py is an alternative (and one of the few workable options if the pages you need to scrape have an important, "structural" role for Javascript operations, esp. AJAX-y ones, since Mechanize doesn't execute the Javascript on the pages it's