![](/img/trans.png)
[英]Beautiful Soup 4: extracting text only from a tag containing children tags
[英]Extracting text from td tag containing br tags inside
我想從內部包含br標簽的td標簽提取文本。
from bs4 import BeautifulSoup
html = "<td class=\"text\">This is <br/>a breakline<br/><br/></td>"
soup = BeautifulSoup(html, 'html.parser')
print(soup.td.string)
實際輸出: None
預期輸出: This is a breakline
這將為您提供所需的內容:
print(soup.td.text)
這是針對特定的td
標簽的
否則,您還有:
print(soup.text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.