zer*_*lus 3 python beautifulsoup
假设我的HTML是:
<html><body><span>This is my text</span></body></html>
Run Code Online (Sandbox Code Playgroud)
如何获得内部包含内容的字符串表示,即:
<span>This is my text</span>
Run Code Online (Sandbox Code Playgroud)
要获取元素的html表示,只需使用内置str函数:
soup = BeautifulSoup("<html><body><span>This is my text</span></body></html>")
span = soup.find('span')
str(span) # Outputs '<span>This is my text</span>'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4115 次 |
| 最近记录: |