BeautifulSoupでテキストの内容を削除
4456 ワード
Data
>>> type(ips)
<class 'bs4.element.Tag'>
>>> print ips
<p>64.158.31.142:3128 Level3
42.104.84.107:8080
110.37.216.6:8080
54.70.50.55:3128 (Merck )
182.253.121.33:8080
Code
>>> type(ips.find_all(text=True))
<class 'bs4.element.ResultSet'>
>>> res = ips.find_all(text=True)
>>> for str in res:
print str
117.4.136.145:8080
188.166.83.6:1080
138.197.157.44:1080
83.56.123.0:3128
183.89.210.22:8080
111.62.243.64:80
or
>>> for str in ips.descendants:
if type(str) == type(ips):
None
else:
print str.string
117.4.136.145:8080
188.166.83.6:1080
138.197.157.44:1080
83.56.123.0:3128
183.89.210.22:8080
111.62.243.64:80
リファレンス
1.Beautifulsoupドキュメント
2.ネットユーザーの方法を知っている
3. arsing unclosed
tags with BeautifulSoup