28

我正在使用 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.

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

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

4

1 回答 1

37

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

import warnings
warnings.filterwarnings("ignore", category=UserWarning, module='bs4')
于 2017-01-05T22:50:54.107 回答