Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress warning of url in beautifulsoup

Tags:

python

bs4

I'm using Beautiful Soup 4 to parse some html-formatted text, scraped from the Internet. Sometimes this text is simply the link to some website. A fact that BS4 is very cross about:

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?

like image 833
Jmaa Avatar asked Mar 16 '16 15:03

Jmaa


1 Answers

To simply suppress the warning and continue with processing this works:

import warnings warnings.filterwarnings("ignore", category=UserWarning, module='bs4') 
like image 188
legel Avatar answered Oct 09 '22 04:10

legel