首页 > 解决方案 > AngularJS - Selenium - 如何获取选项标签值

问题描述

仅出于学术目的,我试图获取列表的所有选项值。我尝试使用通过 ID 查找来使用硒和美丽的汤,但我得到了错误。任何建议将不胜感激。

<div class="ec-combo-box__wrapper" data-ng-class="{ 'mds-container--dark-gray': false }">    <!-- ngIf: labels.contains('caption') -->
<select data-ng-model="ngModel" data-ng-disabled="parameters.disabled" id="ec-screener-filters-securities-combo-box[branding-company-id]" class="ec-combo-box__select ng-not-empty select2-hidden-accessible ng-dirty ng-valid-parse" data-ng-class="{ 'mds-form--error': addErrorClass() }" data-ng-options="parameters.runtimeSelectLabel &amp;&amp; labels.contains(listItem[settings.get('valueField')]) ?
             labels.get(listItem[settings.get('valueField')]) : listItem[settings.get('valueField')]
            for listItem in model.listItems track by listItem[settings.get('keyField')]" aria-invalid="false" tabindex="-1" aria-hidden="true"><!-- ngIf: placeholder --><option data-ng-if="placeholder" value="" class="ng-binding ng-scope">Select a Fund Provider</option><!-- end ngIf: placeholder --><option label="All" value="null" selected="selected">All</option><option label="7IM" value="BN00000BPZ">7IM</option><option label="Abacus"

我想获取所有选项标签 vale 的列表,例如“7IM”

标签: pythonangularjsseleniumbeautifulsoupoption

解决方案


用于find_all查找所有option标签,然后label像这样访问属性:

soup = BeautifulSoup(html, 'html.parser')
options = []
for item in soup.find_all('option'):
    options += [item['label']]

推荐阅读