【发布时间】:2017-03-11 05:14:29
【问题描述】:
我有一个包含一行和几列的 HTML 表格。我想从文本为“Total”的列中提取数据,从值为“93”的列中提取数据 只是这两列我想提取数据。我的代码正在从所有列中提取数据。
例如我的输出是:
Total
93
93
0
0
我想要的输出是:
Total 93
我的代码是:
def extract_total_from_report_htmltestrunner():
filename = (
r"C:\test_runners 2 edit project\selenium_regression_test\TestReport\ClearCore_Automated_GUI_Regression_TestReport.html")
html_report_part = open(filename, 'r')
soup = BeautifulSoup(html_report_part, "html.parser")
tr_total_row = soup.find('tr', {'id': 'total_row'})
tr_total_row.find(text=True, recursive=False)
print tr_total_row.text
return tr_total_row.text
HTML sn-p 是:
<table id='result_table'>
<tr id='total_row'>
<td>Total</td>
<td>93</td>
<td>93</td>
<td>0</td>
<td>0</td>
<td> </td>
</tr>
</table>
如何提取“Total”“93”并在同一行打印出来?
谢谢,里亚兹
【问题讨论】:
标签: python-2.7 selenium-webdriver beautifulsoup