BeatifulSoup3 ではそんな
BeatifulSoup4 だと、
足りない
BeautifulSoup("<a><b /></a>") # <html><head></head><body><a><b></b></a></body></html>
この動作で
嬉しくない
参考
python - Don’t put html, head and body tags automatically, beautifulsoup - Stack Overflow
Beautiful Soup Documentation — Beautiful Soup 4.4.0 documentation
除去する 方法
1. html の parser を 変更する。
python のhtml.parser
を
html タグ、
BeautifulSoup("<a></p>", "html.parser") # <a></a>
2. parser は、 変更せず、soup.body.hidden = True
とする。
以下で、
非表示に
soup = BeautifulSoup(html) soup.body.hidden = True return str(soup.body)
上記、
後日、
The code that caused this warning is on line 170 of the file /usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py. To get rid of this warning, change code that looks like this: BeautifulSoup([your markup]) to this: BeautifulSoup([your markup], "html5lib") markup_type=markup_type))
Beautiful Soup 4.x では
に
parser を
soup = BeautifulSoup(html, "html5lib") soup.body.hidden = True return str(soup.body)
どちらを 採用したか
parser を
今回は、
soup.body.hidden = True
と
以上です。
コメント