简体   繁体   English

抑制beautifulsoup中url的警告

[英]Suppress warning of url in beautifulsoup

I'm using Beautiful Soup 4 to parse some html-formatted text, scraped from the Internet.我正在使用 Beautiful Soup 4 来解析一些从互联网上抓取的 html 格式的文本。 Sometimes this text is simply the link to some website.有时,此文本只是指向某个网站的链接。 A fact that BS4 is very cross about: 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.

I'm very aware of this fact, I just want to interpret the text input, not get a lecture.我很清楚这个事实,我只是想解释文本输入,而不是听课。 I use the console for monitoring the activities of the script, and it's being cluttered by a very angry library.我使用控制台来监控脚本的活动,它被一个非常生气的库弄得乱七八糟。

Any way to suppress or disable this warning?有什么方法可以抑制或禁用此警告?

To simply suppress the warning and continue with processing this works:要简单地抑制警告并继续处理此工作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM