python - 如何使用 Beautiful 或 Selenium 在 Python 中基于 div id 获取 aria-label 作为文本
问题描述
<div id="i19" class="quantumWizTogglePapercheckboxEl appsMaterialWizTogglePapercheckboxCheckbox docssharedWizToggleLabeledControl freebirdThemedCheckbox freebirdThemedCheckboxDarkerDisabled freebirdMaterialWidgetsToggleLabeledCheckbox isCheckedNext isChecked" jscontroller="EcW08c" jsaction="keydown:I481le;dyRcpb:dyRcpb;click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; mouseleave:JywGue; focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;touchstart:p6p2H; touchmove:FwuNnf; touchend:yfqBxc(preventMouseEvents=true|preventDefault=true); touchcancel:JMtRjd;" jsshadow="" jsname="FkQz1b" aria-label="Al-Baraka Bank Limited" data-answer-value="Al-Baraka Bank (Pakistan) Limited" role="checkbox" aria-checked="true" tabindex="0">
嗨,我正在尝试Al-Baraka Bank Limited
使用 div id获取放置在此 div 中的 aria-label 内的文本i19
。基本上我点击了一个复选框,我希望将文本(即 aria-label)保存到一个变量中,以便我可以在其他地方再次使用它。
解决方案
如果该id是unique
,那么您可以get_attribute
获取属性值。
aria_label = driver.find_element(By.ID, "i19").get_attribute('aria-label')
print(aria_label)
推荐阅读
- android - 将值从活动传递到片段得到 NullPointerException 错误
- botframework - 我们可以在任务模块中有不同的图标和名称吗
- maven - 为什么在 mvnrepository.com 或 nexus 等 maven 存储库中没有“最新”版本标签?
- php - Laravel 5.8 作业的参数太少错误
- c# - 开启 IObservable
>> - node.js - pm2中的方形符号是什么意思?
- django - 为什么 models.EmbeddedModelField 不适用于 djongo/django?
- html - 为什么我的 div 列溢出,如何使它们与容器齐平?
- c# - Visual Studio 2017 调试在调用 DateTime.Now 时冻结并中止;
- c - 如何在C中提取指针大小