繁体   English   中英

我想在使用 python mechanize 进行身份验证后获取站点的源。 HTTP 错误 403:禁止

[英]I want to obtain source of a site after authentication with python mechanize. HTTP Error 403: Forbidden

import mechanize
import http.cookiejar as cookielib

br = mechanize.Browser()

cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)

br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

br.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')]

br.open('https://vortex.gg/account/signin')
br._factory.is_html = True
br.select_form(nr=0)
br.form['Username'] = '***************'
br.form['Password'] = '***************'
#i am not sure about this proxy
br.set_proxies({"http":'104.238.176.152:8080'})
r = br.submit()
html = r.read()
#i wanna see html code after autentification
f = open('source_vox.html', 'w')
f.write(html)
f.close

* 回溯(最近一次调用):文件“test_vox.py”,第 19 行,在 br.open(' https://vortex.gg/account/signin ') 文件“/usr/lib/python2.7/dist -packages/mechanize/_mechanize.py", line 253, in open return self._mech_open(url_or_request, data, timeout=timeout) File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py",第 309 行,在 _mech_open 引发响应 mechanize._response.httperror_seek_wrapper:HTTP 错误 403:禁止 *

  • 有没有办法弄清楚这个任务? 它可以与请求模块一起使用吗? *

页面https://vortex.gg/account/signin无法访问。 因此那个错误。 我认为这不是一个 python 错误,而是一个简单的事实,即您没有足够的授权来访问该页面。 即使您复制并粘贴到浏览器,也会出现相同的错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM