简体   繁体   English

如何从具有相同 class 的元素中获取所有 aria-label 值

[英]how can i get all the aria-label values from element with the same class

right now i am working on a program that counts the reactions from facebook posts and these reactions are stored in each arial label with the exact number of reacts and type and i am having a trouble with geting the value of these aria labels because they blong to the same class i am trying to find the aria label of each span here is the python code i tried:现在我正在开发一个程序来计算来自 facebook 帖子的反应,这些反应存储在每个 arial label 中,具有反应的确切数量和类型,我无法获得这些 aria 标签的值,因为它们属于同样的 class 我试图找到每个跨度的 aria label 这里是我试过的 python 代码:

the python code: python 代码:

    element=driver.find_element_by_class_name("_10tn")

    val=element.get_attribute("aria-label")

    print(val)

output is: output 是:

none没有任何

this is the html code:这是 html 代码:

<div class="scrollAreaColumn" id="u_0_f_rK">
<span class="_10tn" data-store='{"reactionType":"all"}' data-sigil="reaction_profile_sigil">
    <span aria-label="5K people reacted to this post" class="_5p-9" role="button" id="u_0_g_oN" data-sigil="reaction_profile_tab_count" style="color: rgb(88, 144, 255);"></span>
</span>
<span class="_10tn" data-store='{"reactionType":1}' data-sigil="reaction_profile_sigil">
    <span aria-label="3.8K people reacted with Like" class="_5p-9 _5p-l" role="button" id="u_0_h_l7"><i class="_2ep2 img sp_CEOlFfsk4vS_1_5x sx_1c460a"></i><span data-sigil="reaction_profile_tab_count"></span></span>
</span>
<span class="_10tn" data-store='{"reactionType":2}' data-sigil="reaction_profile_sigil">
    <span aria-label="721 people reacted with Love" class="_5p-9 _5p-l" role="button" id="u_0_i_V4"><i class="_2ep2 img sp_CEOlFfsk4vS_1_5x sx_07b50e"></i><span data-sigil="reaction_profile_tab_count"></span></span>
</span>
<span class="_10tn" data-store='{"reactionType":4}' data-sigil="reaction_profile_sigil">
    <span aria-label="373 people reacted with Haha" class="_5p-9 _5p-l" role="button" id="u_0_j_5d"><i class="_2ep2 img sp_CEOlFfsk4vS_1_5x sx_6cfcef"></i><span data-sigil="reaction_profile_tab_count"></span></span>
</span>
<span class="_10tn" data-store='{"reactionType":16}' data-sigil="reaction_profile_sigil">
    <span aria-label="36 people reacted with Care" class="_5p-9 _5p-l" role="button" id="u_0_k_xP"><i class="_2ep2 img sp_CEOlFfsk4vS_1_5x sx_81803b"></i><span data-sigil="reaction_profile_tab_count"></span></span>
</span>
<span class="_10tn" data-store='{"reactionType":3}' data-sigil="reaction_profile_sigil">
    <span aria-label="9 people reacted with Wow" class="_5p-9 _5p-l" role="button" id="u_0_l_pR"><i class="_2ep2 img sp_CEOlFfsk4vS_1_5x sx_8928a7"></i><span data-sigil="reaction_profile_tab_count"></span></span>
</span>
<span class="_10tn" data-store='{"reactionType":7}' data-sigil="reaction_profile_sigil">
    <span aria-label="2 people reacted with Sad" class="_5p-9 _5p-l" role="button" id="u_0_m_9o"><i class="_2ep2 img sp_CEOlFfsk4vS_1_5x sx_d4b875"></i><span data-sigil="reaction_profile_tab_count"></span></span>
</span>
<span class="_10tn" data-store='{"reactionType":8}' data-sigil="reaction_profile_sigil">
    <span aria-label="2 people reacted with Angry" class="_5p-9 _5p-l" role="button" id="u_0_n_8t"><i class="_2ep2 img sp_CEOlFfsk4vS_1_5x sx_2b6fe6"></i><span data-sigil="reaction_profile_tab_count"></span></span>
</span>
<div class="_10tl" style="background: rgb(88, 144, 255); width: 31px; left: 0px;"></div>
Labels = [x.get_attribute('aria-label') for x in driver.find_elements_by_xpath("//span[@class='_10tn']/span")]
print(Labels)

Just loop all the spans with that class.只需使用 class 循环所有跨度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM