Pra*_*nav 2 screen-scraping urllib2 beautifulsoup web-scraping python-requests
例如,
<ul>
<li>
<b>Hey, sexy!</b>
Hello
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我只想要li标签中的"Hello" .
如果我使用soup.find("ul").li.text它也包括b标签.
你可以使用这样的find功能
from bs4 import BeautifulSoup
html = '''<ul><li><b>Hey, sexy!</b>Hello</li></ul>'''
soup = BeautifulSoup(html)
print soup.find('li').find(text=True, recursive=False)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3172 次 |
| 最近记录: |