【发布时间】:2019-04-06 21:16:15
【问题描述】:
我正在为工作抓取一个网站,但我无法让 Beautiful soup 抓取异常标签之间的某些文本。
我只是搜索了一个 span 标签,它显示在结果中,但是我无法在不久之后使用 re.compile 获得要显示的特定单词。
这是一个html片段
ng-hide="col.isHidden || col.alwaysHide" ng-class="{'td-content-title':col.isContentTitle}" responsive-table-cell="ctrl.getCellData(col, row)" aria-hidden="false"></td><!----><td ng-repeat="col in ctrl.tableConfig.columns" data-column-title="Result " ng-hide="col.isHidden || col.alwaysHide" ng-class="{'td-content-title':col.isContentTitle}" responsive-table-cell="ctrl.getCellData(col, row)" aria-hidden="false"><span class="test-case-result status-2">Passed</span></td><!----><td ng-repeat="col in ctrl.tableConfig.columns" data-column-title="Approval " ng-hide="col.isHidden || col.alwaysHide" ng-class="{'td-content-title':col.isContentTitle}" responsive-table-cell="ctrl.getCellData(col, row)" aria-hidden="false"><span class="test-case-approval-status status-1">Pending</span></td><!----><td ng-repeat="col in ctrl.tableConfig.columns" data-column-title="Time Left " ng-hide="col.isHidden || col.alwaysHide" ng-class="{'td-content-title':col.isContentTitle}"
这是用于抓取所有跨度标签的代码
soup.find_all('span')
但是当我使用类似的东西时
soup.find_all('span', {re.compile('Passed|Failed')}):
似乎没有结果
我也试过了
soup.find_all('span', {'test-case-result status-2': re.compile('Passed|Failed')})
预期 - 所有通过和失败的实例都将被删除
实际 - 除了纯粹使用 span tage 之外的所有抓取尝试都显示为空。
我确信这很简单,我遗漏了一些东西,但我真的很难进一步了解文档。感谢您的帮助。
【问题讨论】:
-
将网址添加到此页面。
-
soup.find_all('span', text=re.compile('Passed|Failed')) -
@furas 我不能担心它的工作,所以它在登录墙后面
-
在
find_all()中尝试text=re.compile(...) -
@furas 你明白了。非常感谢。你能输入它作为答案,以便我接受吗?
标签: regex python-3.x web-scraping beautifulsoup