我想在使用 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”,第 253 行,打开 return self._mech_open(url_or_request, data, timeout=timeout) 文件“/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 错误,而是您没有足够的授权来访问该页面这一事实很简单。即使你复制并粘贴到浏览器,你也会得到同样的错误。