【问题标题】:AngularJS - Selenium- How to get the option label valueAngularJS - Selenium - 如何获取选项标签值
【发布时间】:2019-01-21 20:43:52
【问题描述】:

仅出于学术目的,我试图获取列表的所有选项值。我尝试使用通过 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"

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

【问题讨论】:

  • 添加 html 的截图是不好的做法,添加 html snip 并且您的代码会尝试遇到错误
  • 我很抱歉。我改了

标签: python angularjs selenium beautifulsoup option


【解决方案1】:

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

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

【讨论】:

  • pyankoff 我试图运行它,但它在网站上提供了一个选项列表,与我附上的图片中的选项列表不同。不过谢谢你的回答
  • 我修改了,你可以看到
猜你喜欢
  • 1970-01-01
  • 2012-10-02
  • 2019-12-29
  • 2016-07-28
  • 2011-01-11
  • 1970-01-01
  • 2019-01-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多