mechanize

Error logging into instagram with python

孤人 提交于 2020-01-04 05:10:46
问题 I am trying to log into my instagram via a python script using argparse. It seems to connect but it prints out " This page could not be loaded. If you have cookies disabled in your browser, oryou are browsing in Private Mode, please try enabling cookies or turning off Private Mode, and then retrying your action. " Here's my code: import argparse import mechanicalsoup from bs4 import BeautifulSoup parser = argparse.ArgumentParser(description='Login to Instagram.') parser.add_argument("username

autodetect proxy setting linux

坚强是说给别人听的谎言 提交于 2020-01-04 00:58:12
问题 I am writing a python app that needs to send and retrieve some information from Internet. I would like to auto-detect the proxy setting (to avoid asking the user to set up the proxy configuration). It seems that urllib can do this on Windows and Mac OsX and not on Unix/Linux. I need/prefer to use the mechanize module, instead of urllib/urllib2. (It is easier to handle data encoded as "multipart/form-data). Can the mechanize module auto-detect the proxy setting? If true, it will work on

Ruby Mechanize Zlib::BufError

只谈情不闲聊 提交于 2020-01-03 11:52:27
问题 Not sure why I'm getting this error now with the Mechanize gem - been using it for a while now with no issues. My script will randomly stop and throw the following error: /Users/username/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:798:in `rescue in response_content_encoding': error handling content-encoding gzip: buffer error (Zlib::BufError) (Mechanize::Error) Any ideas? 回答1: It's possible that you're hitting a URL that points to a load-balancer. One of the

Ruby Mechanize Zlib::BufError

我只是一个虾纸丫 提交于 2020-01-03 11:51:49
问题 Not sure why I'm getting this error now with the Mechanize gem - been using it for a while now with no issues. My script will randomly stop and throw the following error: /Users/username/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:798:in `rescue in response_content_encoding': error handling content-encoding gzip: buffer error (Zlib::BufError) (Mechanize::Error) Any ideas? 回答1: It's possible that you're hitting a URL that points to a load-balancer. One of the

Python - Mechanize sessions are not regonized

自作多情 提交于 2020-01-02 08:57:12
问题 I'm behind a proxy in a company. And in order to access some intra-sites, I have to login first to a specific site. The thing is if I login to this specific site from IE or FF, then I can access the intra-sites not necessarily from the same browser where I logged in. For ex: I logged in from FF, then I can access the intra-sites from IE and vice versa (and I get ping reply from the intra-sites). But, when I login using mechanize and while keeping the session alive (by using sleep ), I can not

Use python mechanize to log into pages with NTLM authentication

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-02 05:33:29
问题 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 =

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

僤鯓⒐⒋嵵緔 提交于 2020-01-02 04:42:09
问题 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. 回答1: Use the set_cookie method: >>> import mechanize >>> br=mechanize.Browser() >>> br.set_cookie? Definition: br.set_cookie(self, cookie_string) Docstring: Request to

How to select a Radio Button?

耗尽温柔 提交于 2020-01-02 01:53:08
问题 I am using mechanize and I am trying to select a button from a radio button list. This list has 5 items. How can I select the first item? Docs didn't help me. >>> br.form <ClientForm.HTMLForm instance at 0x9ac0d4c> >>> print(br.form) <form1 POST http://www.example.com application/x-www-form-urlencoded <HiddenControl(DD=17010200) (readonly)> <RadioControl(prodclass=[1, 2, 3, 4, 5])> <SubmitControl(submit=text) (readonly)>> 回答1: It should be as simple as br.form['prodclass'] = ['1'] I prefer

How do I print out the cookies that Mechanized has stored?

一个人想着一个人 提交于 2020-01-01 11:21:43
问题 I'm using mechanize to login into a website and then retrieve a page. I'm running into some problems and I suspect this is due to some values in the cookies. When Mechanize logs into a website I assume it stores the cookies. How do I print out all the data stored in the cookies by Mechanize? 回答1: The agent has a cookies methods. agent = Mechanize.new page = agent.get("http://www.google.com/") agent.cookies agent.cookies.to_s The cookies return is a Mechanize::Cookies object 来源: https:/

how to add new field to mechanize form (ruby/mechanize)

时光毁灭记忆、已成空白 提交于 2020-01-01 08:36:06
问题 there is a public class method to add field to mechanize form I tried .. #login_form.field.new('auth_login','Login') #login_form.field.new('auth_login','Login') and both gives me an error undefined method "new" for #<WWW::Mechanize::Form::Field:0x3683cbc> (NoMethodError) I tried login_form.field.new('auth_login','Login') which gives me an error mechanize-0.9.3/lib/www/mechanize/page.rb:13 n `meta': undefined method `search' for nil:NilClass (NoMethodError) but at the time I submit the form.