mechanize

How to fix encoding in Python Mechanize?

╄→尐↘猪︶ㄣ 提交于 2019-12-09 13:08:59
问题 here is the sample code: from mechanize import Browser br = Browser() page = br.open('http://hunters.tclans.ru/news.php?readmore=2') br.form = br.forms().next() print br.form The problem is that server return incorrect encoding (windows-cp1251). How can I manually set the encoding of the current page in mechanize? Error: Traceback (most recent call last): File "/tmp/stackoverflow.py", line 5, in <module> br.form = br.forms().next() File "/usr/local/lib/python2.6/dist-packages/mechanize/

Python Mechanize select form FormNotFoundError

我的梦境 提交于 2019-12-09 09:21:39
问题 I want to select a form with mechanize. This is my code: br = mechanize.Browser() self.br.open(url) br.select_form(name="login_form") The form's code: <form id="login_form" onsubmit="return Index.login_submit();" method="post" action="index.php?action=login&server_list=1"> But I'm getting this Error: mechanize._mechanize.FormNotFoundError: no form matching name 'login_form 回答1: The problem is that your form does not have a name, only an id, and it is login_form . You can use a predicate: br

Getting and trapping HTTP response using Mechanize in Python

瘦欲@ 提交于 2019-12-09 08:58:14
问题 I am trying to get the response codes from Mechanize in python. While I am able to get a 200 status code anything else isn't returned (404 throws and exception and 30x is ignored). Is there a way to get the original status code? Thanks 回答1: Errors will throw an exception, so just use try:...except:... to handle them. Your Mechanize browser object has a method set_handle_redirect() that you can use to turn 30x redirection on or off. Turn it off and you get an error for redirects that you

mechanize (python) click on a javascript type link

偶尔善良 提交于 2019-12-09 03:42:29
问题 is it possible to have mechanize follow an anchor link that is of type javascript? I am trying to login into a website in python using mechanize and beautifulsoup. this is the anchor link <a id="StaticModuleID15_ctl00_SkinLogin1_Login1_Login1_LoginButton" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("StaticModuleID15$ctl00$SkinLogin1$Login1$Login1$LoginButton", "", true, "Login1", "", false, true))"><img id="StaticModuleID15_ctl00_SkinLogin1_Login1_Login1_Image2"

What can I do about Mechanize waiting on an unresponsive web site?

放肆的年华 提交于 2019-12-08 22:08:28
问题 I noticed that when I fetch a site that is not responding using Mechanize, it just keeps on waiting. How can I overcome this problem? 回答1: There's a couple ways to deal with it. Open-Uri, and Net::HTTP have ways of passing in timeout values, which then tell the underlying networking stack how long you are willing to wait. For instance, Mechanize lets you get at its settings when you initialize an instance, something like: mech = Mechanize.new { |agent| agent.open_timeout = 5 agent.read

reverse-lookup Digital Object Identifier given table of citations?

[亡魂溺海] 提交于 2019-12-08 17:33:52
问题 I have a table of citations that includes the last name of the first author, the title, journal, year, and page numbers for each citation. I have posted the first few lines of the table on google docs, or the csv version (not all records have a doi) I would like to be able to query the digital object identifier for each of these citations. For the titles, it would be best if the query could handle "fuzzy matching". How can I do this? The table is currently in MySQL, but it would be sufficient

perl-mechanize runs into limitations - several debugging attempts started

孤街醉人 提交于 2019-12-08 15:28:56
问题 hello dear developers. first of all - sorry for being the newbie.. i am pretty new to Perl. i am trying to learn something about perl while playin around with code - and snippets. Today i have a little script that runs a mechanize job.. but somewhat does not run to the end. Waht is aimed: i want to get some thumbnails of wesite-sceenshots. well i run this script , which is written to do some screenshots of websites i have also up and running mozrepl. whats strange is the output - see below...

WWW::Mechanize::Firefox - installation-troubles on OpenSuse-Linux version 12.1

血红的双手。 提交于 2019-12-08 14:11:09
问题 good day dear fellow perl-programmers. i have serious install-troubles with WWW::Mechanize::Firefox on OpenSuse 12.1 (which is a linux system that is used here in Europe): see the issues that i noticed in the command-line: cpan shell -- CPAN exploration and modules installation (v1.960001) Enter 'h' for help. cpan[1]> install WWW::Mechanize::Firefox; Fetching with HTTP::Tiny: http://artfiles.org/cpan.org/authors/01mailrc.txt.gz Going to read '/root/.cpan/sources/authors/01mailrc.txt.gz' .....

How do I merge multiple Hashes into a single valid JSON file?

喜你入骨 提交于 2019-12-08 13:50:18
问题 I'm using the following code to generate a JSON file containing all category information for a particular website. require 'mechanize' @categories_hash = {} @categories_hash['category'] ||= {} @categories_hash['category']['id'] ||= {} @categories_hash['category']['name'] ||= {} @categories_hash['category']['group'] ||= {} @categories_hash['category']['search_attributes'] ||= {} # Initialize Mechanize object a = Mechanize.new # Open file and begin File.open("json/booyah/#{Time.now.strftime '%Y

Mechanize/OWA user/password error

巧了我就是萌 提交于 2019-12-08 13:39:28
问题 I'm trying to use Mechanize to get emails from my Outlook web client, but I'm having troubles logging in. It gives me the errors listed below. I've verified that the user name and password are correct. Any ideas? Here is my code: import mechanize b = mechanize.Browser() cj = cookielib.LWPCookieJar() b.set_cookiejar(cj) b.open('https://mail.example.com/owa/') br.select_form("logonForm") b['username'] = 'myname' b['password'] = 'password' b.submit() I can see that form components are being