mechanize-python

how to set cookie in python mechanize

不想你离开。 提交于 2019-12-21 05:00:27
问题 After sending request to the server br.open('http://xxxx') br.select_form(nr=0) br.form['MESSAGE'] = '1 2 3 4 5' br.submit() I get the response title, which has set-cookie Set-Cookie: PON=xxx.xxx.xxx.111; expires=Tue, 17-Mar-2015 00:00:00 GMT; path=/ Because mechanize seems to be not able to remember the cookie, so I want to set cookie for br. How can I do it? cj = mechanize....? br.set_cookiejar(cj) I have no idea. Please help 回答1: I think that this should do what you want: import Cookie

CertificateError: hostname doesn't match

放肆的年华 提交于 2019-12-21 04:03:07
问题 I'm using a proxy (behind corporate firewall), to login to an https domain. The SSL handshake doesn't seem to be going well: CertificateError: hostname 'ats.finra.org:443' doesn't match 'ats.finra.org' I'm using Python 2.7.9 - Mechanize and I've gotten past all of the login, password, security questioon screens, but it is getting hung up on the certification. Any help would be amazing. I've tried the monkeywrench found here: Forcing Mechanize to use SSLv3 Doesn't work for my code though. If

mechanize: first form works, then “unknown GET form encoding type 'utf-8'”

六月ゝ 毕业季﹏ 提交于 2019-12-13 05:15:12
问题 I am trying to fill out 2 forms from the EUR-Lex website in order to record some data from the generated webpage. I am stuck at form #2. I get the feeling this should be easy and I've researched a bit, but no luck. import mechanize froot = '...' f = open(froot + 'text.html', 'w') br = mechanize.Browser() br.open('http://eur-lex.europa.eu/RECH_legislation.do') br.select_form(name='form2') br['T1'] = ['V112'] br['T3'] = ['V2'] br['T2'] = ['V1'] first_page = br.submit() f.write(first_page.get

Python Beautiful Soup parsing a UTF-8 coded table (using mechanize)

孤街醉人 提交于 2019-12-13 04:48:31
问题 I'm trying to parse the following table, coded in UTF-8 (this is part of it): <table cellspacing="0" cellpadding="3" border="0" id="ctl00_SPWebPartManager1_g_c001c0d9_0cb8_4b0f_b75a_7cc3b6f7d790_ctl00_HistoryData1_gridHistoryData_DataGrid1" style="width:100%;border-collapse:collapse;"> <tr class="gridHeader" valign="top"> <td class="titleGridRegNoB" align="center" valign="top"><span dir=RTL>שווי שוק (אלפי ש"ח)</span></td><td class="titleGridReg" align="center" valign="top">הון רשום למסחר</td>

Proxy seems to be ignored by Mechanize?

微笑、不失礼 提交于 2019-12-12 19:20:20
问题 I am using an http proxy and the Mechanize module. I initialize the mechanize object and set the proxy like so: self.br = mechanize.Browser() self.br.set_proxies({"http": proxyAddress}) #proxy address is like 1.1.1.1:8080 Then I open the site like so: response = self.br.open("http://google.com") My problem is that mechanize seems to be completely ignoring the proxy. If I debug and inspect the br object, under the proxy handler I can see my proxy settings. However, even if I give a bad proxy

Mechanize Python and addheader method - how do I know the newest headers?

Deadly 提交于 2019-12-11 03:33:57
问题 Currently, I'm using mechanize like this: browser = mechanize.Browser() browser.set_handle_robots(False) browser.set_handle_equiv(False) browser.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] However, operating systems and browsers get updated and I assume that this header: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1 should be updated as well. Is

Python mechanize form submitting doesn't work

我只是一个虾纸丫 提交于 2019-12-10 10:29:34
问题 I am trying to write a simple bot that would login to my account on a page and then comment other users' images. However I am not able to get the comment form submitting work correctly. The comment form looks like this: <form id="comment-form" action="#" onsubmit="postComment($(this).serialize(),'image',117885,229227); return false;"> <input class="comment" type="text" size="40" name="comment" id="comment" /> <input type="hidden" name="commentObj" value="9234785" /> <input type="hidden" name=

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

Cloning mechanize.Browser yields to an error

假如想象 提交于 2019-12-08 08:38:52
问题 I am currently trying to send multiple requests with the mechanize.Browser object at once and my approach was to start some threads. Each thread should clone the mechanize.Browser object and send the requests. But copying the object causes a TypeError: TypeError: object.__new__(cStringIO.StringO) is not safe, use cStringIO.StringO.__new__() But I can't figure out how to get it running. After opening some pages I spawn the threads and do: newbr = copy.deepcopy(br) which causes the error. Any

Verifying br.submit() using Python's Mechanize module

走远了吗. 提交于 2019-12-08 02:14:52
问题 Just trying to login to a website using mechanize. When I print "br.form", I can see my credentials entered into my form. But I do not know how to actually submit the form properly. I use "br.submit()" and attempt to verify it has proceeded to the next page by printing the br.title(), but the title appearing is for the login screen, and not the post-login screen. import mechanize from time import sleep def reportDownload(): # Prompt for login credentials print("We require your credentials.")