【发布时间】:2021-06-01 15:28:30
【问题描述】:
我正在尝试为公共记录构建网络抓取工具。目前,我的 HTML 有几个带有属性信息的“卡片”,包括地址和作品集编号。每张卡片都有以下 HTML。
<div class="results_record ng-scope" ng-repeat="candidate in candidatesList.candidates | orderBy:['siteAddress']">
<span class="record_number ng-binding">1</span>
<div class="record_folio ng-binding"><strong>FOLIO:</strong>
<span ng-click="getCandidateFolio(candidate.folio)" class="ng-binding">01-4138-159-0001</span> (Reference)
</div>
</div><!-- end ngRepeat: candidate in candidatesList.candidates | orderBy:['siteAddress'] --><div class="results_record ng-scope" ng-repeat="candidate in candidatesList.candidates | orderBy:['siteAddress']">
我想为每张卡片选择作品集编号文本(即本示例中的 01-4138-159-0001)。我的代码如下,使用 Python 的 Selenium,但我没有得到任何结果:
folios = driver.find_elements_by_xpath('//span[@ng-click="getCandidateFolio(candidate.folio"]')
for folio in folios:
print(folio.text)
有没有更好的选择对开编号的方法?
【问题讨论】:
-
您是否收到任何错误消息?此外,您还没有在 Candidate.folio 之后关闭括号。
-
@RhysFlook 谢谢,关闭括号后,我现在得到:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[@ngclick="getCandidateFolio(candidate.folio)"]"}