我正在抓取一个页面,我必须从这种格式中得到员工的数量:
<h5>Number of Employees</h5>
<p>
20
</p>我需要得到数字"20“问题是,这个数字并不总是在同一个标题中,有时在"h4”中,还有更多的‘h5’标题,所以我需要找到包含在标题中的数据:“员工数量”,并提取包含在包含段落中的数字
这是页面的链接。
http://www.bbb.org/chicago/business-reviews/paving-contractors/lester-s-material-service-inc-in-grayslake-il-72000434/
发布于 2015-11-29 23:37:40
好的,最简单的方法是找到一个包含“员工人数”-text的元素,然后简单地将该段放在后面,假设段落总是紧跟在后面。
下面是一段快速而肮脏的代码,并打印出数字:
parent = soup.find("div", id='business-additional-info-text')
for child in parent.children:
if("Number of Employees" in child):
print(child.findNext('p').contents[0].strip())发布于 2015-11-29 23:40:17
'normalize-space(//*[self::h4 or self::h5][contains(., "Number of Employees")]/following-sibling::p[1]/text())'https://stackoverflow.com/questions/33989262
复制相似问题