在selenium python中获取多个特定标签



我有一个网页,我正在抓取,有多个标签,如下所示:

<div ng-repeat-end="" class="default-group term-" ng-class="{
'course-converting': (!baseCourses.isCourseConversionComplete(cm.course) &amp;&amp; !cm.course.ui.showConversionInProgress),
'last-item': $last
}" ng-init="baseCourses.patchData(cm)">

<bb-base-course-card ng-class="::{'first': baseCourses.isFirstNonFavorite(cm, term).ui.isNeedCreateFTUE}" membership="cm" term="term" delegated-api="baseCourses"><!-- If internal course -->
<!----><div ng-if="!membership.course.ui.isExternal" class="element-card course-element-card highlight pointer bar  js-course-details child-is-invokable course-color-5" data-course-id="_6138_1" bb-click-to-invoke-child="a.course-title" stop-propagation="true" ng-hide="pinned" ng-class="{
'inactive-link': !membership.course.canAccess() || baseCourses.isSetToUltraCourse(membership.course),
'js-complete': membership.course.isComplete(),
'js-updating-conversion-status': membership.course.ui.isUpdatingConversionStatus  || baseCourses.isSetToUltraCourse(membership.course),
'js-conversion-in-progress': membership.course.ui.showConversionInProgress,
'show-focus-outline': baseCourses.isFocusedCourse(membership.course.id),
'set-to-ultra-course': baseCourses.isSetToUltraCourse(membership.course)
}" tabindex="-1" id="course-list-course-_6138_1">

我想要的是来自"bb base course card"标签下div的"data course id"。(在最后一个标签"id"中也很生动,但在"课程列表课程-"后面连接。我也可以使用它。(

有人能帮忙吗???

你能用这个CSS选择器来获得这个div吗?

bb-base-course-card > div

我解决了它。

for item in page.find_elements_by_xpath('//*[@class="default-group term-"]'):
link.append(item.find_element_by_css_selector('bb-base-course-card > div').get_attribute('data-course-id'))

无论如何,谢谢。

相关内容

  • 没有找到相关文章

最新更新