我想从网上刮一张桌子并保留 实体完整,以便我以后可以重新发布为 HTML。BeautifulSoup 似乎正在将这些转换为空格。例子:
from bs4 import BeautifulSoup
html = "<html><body><table><tr>"
html += "<td> hello </td>"
html += "</tr></table></body></html>"
soup = BeautifulSoup(html)
table = soup.find_all('table')[0]
row = table.find_all('tr')[0]
cell = row.find_all('td')[0]
print cell
观察结果:
<td> hello </td>
要求的结果:
<td> hello </td>