【发布时间】:2016-06-10 13:04:24
【问题描述】:
from bs4 import BeautifulSoup
import os
import re
htmlDoc="""
<html>
<body>
<table class="details" border="1" cellpadding="5" cellspacing="2" style="width:95%">
<tr>
<td>Roll No.</td>
<td><b>Subject 1</b></td>
<td>Subject 2</td>
</tr>
<tr>
<td>01</td>
<td>Absent</td>
<td>Present</td>
</tr>
<tr>
<td>02</td>
<td>Absent</td>
<td>Absent</td>
</tr>
</table>
</body>
</html>
"""
soup = BeautifulSoup(htmlDoc,"lxml")
#table = soup.find("table",attrs={class:"details"})
html = soup.prettify("utf-8")
with open("/home/alan/html_/output.html", "wb") as file:
file.write(html)
我使用 BeautifulSoup 编写 HTML 代码。在代码中,我要做的变量是 Present, Absent。更改某些参数后,我必须更改值,将存在更改为不存在,反之亦然。 我必须将 pesent/absent 设为变量 'a'。
【问题讨论】:
-
你能澄清你的问题吗?目前尚不清楚您遇到了什么问题。考虑包含您拥有的输入的一小部分(包括程序变量,而不仅仅是 HTML)以及您想要的确切输出。
标签: python html python-2.7 beautifulsoup