我想从我的Selenium测试报告html文件中提取一些数据。 我得到空白打印到PyCharm控制台。 我想从P标签中获取所有数据。它在一个div标签下。Python BeautifulSoup从html文件p标签中提取内容,该标签位于组div标签中。我正在打印空白
的HTML片段是:
<div class='heading'>
<h1>Test Report</h1>
<p class='attribute'><strong>Start Time:</strong> 2016-08-12 11:57:33</p>
<p class='attribute'><strong>Duration:</strong> 0:48:09.007000</p>
<p class='attribute'><strong>Status:</strong> Pass 75</p>
<p class='description'>Selenium - ClearCore 501 Regression edit project automated test</p>
</div>
由于一开始我还第一次尝试了获取开始时间,看看我能打印值到控制台上。我没有打印出任何东西。 我想获得的描述出来过,硒 - ClearCore 501回归编辑项目的自动化测试
我的代码是:
from bs4 import BeautifulSoup
def extract_data_from_report_htmltestrunner():
filename = (r"C:\share\ClearCore501_Automated_GUI_TestReport.html")
html_report_part = open(filename,'r')
soup = BeautifulSoup(html_report_part, "html.parser")
div_heading = soup.find('div', {'class': 'heading'})
p = div_heading.find('p', text='Start Time:')
print "test"
print p
我已经加入:
if __name__ == "__main__":
extract_data_from_report_htmltestrunner()
我输出现在得到的是:
test
None
我在做什么错误请?
感谢,里亚兹
[*如果一个标签包含一个以上的事情,那么,目前还不清楚应该是指什么.string,所以.string被定义为无*](https://www.crummy.com/software/BeautifulSoup/bs4/doc/#string) – styvane