gpt4 book ai didi

python - "Browser Not Supported"使用BeautifulSoup进行网页抓取时出错

转载 作者:行者123 更新时间:2023-11-30 22:08:42 25 4
gpt4 key购买 nike

我正在尝试网络抓取网站,但我不断收到此“浏览器不支持”错误。有谁知道如何解决这一问题?谢谢。

import bs4
import requests

headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/39.0.2171.95 Safari/537.36'}

session = requests.get("https://revengeofficial.com/webstore", headers=headers)

page = bs4.BeautifulSoup(session.text, "html.parser")

print(page.title.text)

输出:http://prntscr.com/kozv1x

编辑:多次尝试后我仍然找不到解决方案,其他人可以帮忙吗?

最佳答案

以下用户代理似乎可以工作:

import bs4
import requests

headers={'User-Agent': 'Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405'}
session = requests.get("https://revengeofficial.com/webstore", headers=headers)
page = bs4.BeautifulSoup(session.text, "html.parser")

print(page.title.text)

这显示:

WEBSHOP — Revenge — Official Clothing Shop

如果这对您不起作用,请尝试使用其他 IP 地址来发出请求。也可能是您向服务器发出了太多请求。

使用 Python 3.6.3、Requests 2.18.4、BeautifulSoup 4.6.0 进行测试

关于python - "Browser Not Supported"使用BeautifulSoup进行网页抓取时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52112142/

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