【发布时间】:2021-06-10 13:27:17
【问题描述】:
我想从 Upwork 求职搜索中抓取所有工作的标题,这些标题存储在这样的标签中:
<h4 data-job-title="::$ctrl.job" class="job-title m-xs-top-bottom p-sm-right ng-isolate-scope">
<a data-ng-bindhtml="jsuJobTitleController.job.title|truncateHtmlByWords:jsuJobTitleController.getWordsThreshold()" data-ng-click="jsuJobTitleController.onJobTitleClick($event)" data-ng-href="/jobs/Email-Analytics-Custom_~0150c1eb58019b8306/" class="job-title-link break visited ng-binding" data-ng-class="{'text-muted': jsuJobTitleController.isHidden}" data-itemprop="url" href="/jobs/Email-Analytics-Custom_~0150c1eb58019b8306/">
Email Analytics Custom
</a>
</h4>
我尝试过使用其中一种可能的类:
jobs = driver.find_elements_by_xpath('//h4[@class="job-title"]')
还有所有的课程:
jobs = driver.find_elements_by_xpath("//h4[contains(@class, 'job-title') and contains(@class, 'm-xs-top-bottom') and contains(@class, 'p-sm-right') and contains(@class, 'ng-isolate-scope')]")
但是这两种方法都只返回空列表 - 这很奇怪,因为这表明它正在匹配某些东西?因为如果它不能匹配一个元素,我会期待一个错误。
谁能建议如何实现这一目标?
谢谢!
【问题讨论】:
标签: python selenium selenium-webdriver web-scraping xpath