gpt4 book ai didi

python - 使用 python 绕过 HTTP 403

转载 作者:行者123 更新时间:2023-12-03 08:03:10 25 4
gpt4 key购买 nike

我正在制作一个使用谷歌搜索的程序,但我不能因为 HTTP 错误 403 有什么办法可以解决它或我使用 Mechanize 浏览的任何东西是我的代码

from mechanize import Browser

inp = raw_input("Enter Word: ")
Word = inp

SEARCH_PAGE = "https://www.google.com/"

browser = Browser()
browser.open( SEARCH_PAGE )
browser.select_form( nr=0 )

browser['q'] = Word
browser.submit()

这是错误信息
Traceback (most recent call last):
File "C:\Python27\Project\Auth2.py", line 16, in <module>
browser.submit()
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 541, in submit
return self.open(self.click(*args, **kwds))
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 203, in open
return self._mech_open(url, data, timeout=timeout)
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 255, in _mech_open
raise response
httperror_seek_wrapper: HTTP Error 403: request disallowed by robots.txt

请帮忙,谢谢

最佳答案

您可以告诉 Mechanize 忽略 robots.txt文件:

browser.set_handle_robots(False)

关于python - 使用 python 绕过 HTTP 403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16094052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com