我想在使用python机械化认证后获取网站的来源。 HTTP错误403:禁止

问题描述 投票:1回答:1
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

*追溯(最近一次通话):在第19行的文件“ test_vox.py”中br.open('https://vortex.gg/account/signin')打开文件“ /usr/lib/python2.7/dist-packages/mechanize/_mechanize.py”,第253行返回self._mech_open(url_or_request,data,timeout = timeout)_mech_open中的文件“ /usr/lib/python2.7/dist-packages/mechanize/_mechanize.py”,第309行引起回应mechanize._response.httperror_seek_wrapper:HTTP错误403:禁止*

python linux mechanize
1个回答
0
投票
无法访问页面https://vortex.gg/account/signin。因此那个错误。我认为这不是python错误,但简单的事实是您没有足够的授权来访问该页面。即使您复制并粘贴到浏览器中,也会遇到相同的错误。
© www.soinside.com 2019 - 2024. All rights reserved.