mechanize

How to save mechanize.Browser() cookies to file?

 ̄綄美尐妖づ 提交于 2019-12-04 12:43:27
How could I make Python's module mechanize (specifically mechanize.Browser()) to save its current cookies to a human-readable file? Also, how would I go about uploading that cookie to a web page with it? Thanks jizhilong Deusdies,I just figured out a way with refrence to Mykola Kharechko's post #to save cookie >>>cookiefile=open('cookie','w') >>>cookiestr='' >>>for c in br._ua_handlers['_cookies'].cookiejar: >>> cookiestr+=c.name+'='+c.value+';' >>>cookiefile.write(cookiestr) #binding this cookie to another Browser >>>while len(cookiestr)!=0: >>> br1.set_cookie(cookiestr) >>> cookiestr

Mechanize/Ruby read source code of 404 page

青春壹個敷衍的年華 提交于 2019-12-04 12:24:20
All I'm doing is loading mechanize, and getting a page that returns 404. But that's exactly what I want. The 404 page has plenty of html I'd like to use in my example. a = mechanize.new a.get('http://www.youtube.com/watch?v=e4g8jriw4rg') a.page => nil I can't seem to find any further info on this. pguardiario You need to handle the exception: begin page = a.get 'http://www.youtube.com/watch?v=e4g8jriw4rg' rescue Mechanize::ResponseCodeError => e puts e.response_code # the status code as a string, e.g. "404" page = e.page end puts page.title This may have been the case when the answer was

Scraping a site that requires login username and password on two separate pages

房东的猫 提交于 2019-12-04 12:02:21
I'm trying to scrape information from my companies Intranet so that I can display information on our office wall board via dashing dashboard. I'm trying to work with the provided information from: This Site .The problem that I'm having other than being a noob is that in order to gain access to the information I want to scrape, I need to login to our Intranet providing my username on one page then submitting to another so that I can provide my password. Once I'm logged in, I can then link and scrape my data. Here is some source code from my login username page: <form action='loginauthpwd.asp

How to click link in Mechanize and Nokogiri?

老子叫甜甜 提交于 2019-12-04 10:15:37
I'm using Mechanize to scrape Google Wallet for Order data. I am capturing all the data from the first page, however, I need to automatically link to subsequent pages to get more info. The #purchaseOrderPager-pagerNextButton will move to the next page so I can pick up more records to capture. The element looks like this. I need to click on it to keep going. <a id="purchaseOrderPager-pagerNextButton" class="kd-button small right" href="purchaseorderlist?startTime=0&... ;currentPageStart=1&currentPageEnd=25&inputFullText="> <img src="https://www.gstatic.com/mc3/purchaseorder/page-right.png"></a>

Looking for Requests equivalent of Mechanize capabilities

吃可爱长大的小学妹 提交于 2019-12-04 09:49:02
I am interested in seeing if Requests can handle some tasks I have primarily been doing in Mechanize. Mechanize can easily handle filling out forms and submitting forms and I am having a hard time trying to do the same thing in Requests. For example, import mechanize br = mechanize.Browser() url = "https://www.euronext.com/en/data/download?ml=nyx_pd_stocks&cmd=default&formKey=nyx_pd_filter_values%3A18d1ee939a63d459d9a2a3b07b8837a7" br.open(url) br.select_form(nr=1) br.form['format']=['2'] br.form['date_format']=['2'] response = br.submit().read() Would the Requests equivalent not be: import

Which is best in Python: urllib2, PycURL or mechanize?

萝らか妹 提交于 2019-12-04 07:38:44
问题 Ok so I need to download some web pages using Python and did a quick investigation of my options. Included with Python: urllib - seems to me that I should use urllib2 instead. urllib has no cookie support, HTTP/FTP/local files only (no SSL) urllib2 - complete HTTP/FTP client, supports most needed things like cookies, does not support all HTTP verbs (only GET and POST, no TRACE, etc.) Full featured: mechanize - can use/save Firefox/IE cookies, take actions like follow second link, actively

302s and losing cookies with urllib2

我只是一个虾纸丫 提交于 2019-12-04 04:27:39
问题 I am using liburl2 with CookieJar / HTTPCookieProcessor in an attempt to simulate a login to a page to automate an upload. I've seen some questions and answers on this, but nothing which solves my problem. I am losing my cookie when I simulate the login which ends up at a 302 redirect. The 302 response is where the cookie gets set by the server, but urllib2 HTTPCookieProcessor does not seem to save the cookie during a redirect. I tried creating a HTTPRedirectHandler class to ignore the

Python and mechanize login script

﹥>﹥吖頭↗ 提交于 2019-12-04 03:45:02
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 name=id> </P> <P><B>PIN<BR></B><INPUT maxLength=20 type=password name=PIN> </P> <P></P> <P><INPUT value

log in with browser and then ruby/mechanize takes it over?

穿精又带淫゛_ 提交于 2019-12-04 03:38:09
问题 Is that even possible? what I need to pass to mechanize? With what url I can start then? I cannot manage (so far) to log into one website using mechanize so I was thinking if I can do this little workaround. I believe I can capture all cookies and everything else and then pass it to ruby/mechanize to do the rest ... screenshots below are made using firebug ( Firebug logs the POST or GET request, the response headers ) login that works = just one line and html for login that works <script type

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

馋奶兔 提交于 2019-12-04 02:19:43
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. The field does not exist in html source. I want to add it so POST query sent by my script will contain