gpt4 book ai didi

python - 禁止在 beautifulsoup 中显示 url 警告

转载 作者:IT老高 更新时间:2023-10-28 21:02:11 29 4
gpt4 key购买 nike

我正在使用 Beautiful Soup 4 来解析一些从 Internet 上抓取的 html 格式的文本。有时,此文本只是指向某个网站的链接。 BS4 非常不满意的一个事实:

UserWarning: "http://example.com" looks like a URL. Beautiful Soup is not
an HTTP client. You should probably use an HTTP client to get the document
behind the URL, and feed that document to Beautiful Soup.

我很清楚这个事实,我只想解释文本输入,而不是听讲座。我使用控制台来监视脚本的事件,它被一个非常愤怒的库弄得乱七八糟。

有什么方法可以禁止或禁用此警告?

最佳答案

要简单地抑制警告并继续处理此工作:

import warnings
warnings.filterwarnings("ignore", category=UserWarning, module='bs4')

关于python - 禁止在 beautifulsoup 中显示 url 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36039724/

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