在 python: splinter 中,我如何在未认可的 linkedin 技能上使用 .click()?

In python: splinter, how can I .click() on un-endorsed linkedin skills?

之前的研究

我已经阅读了 splinter 帮助文档并搜索了 Stack Overflow,并花了大约 4 个小时尝试各种想法,主要是将 dir() 与 firefox 的 "inspect element" 功能结合使用。没有成功。

问题

我正在努力弄清楚如何在 Linkedin 中自动认可我的连接技能,将交互限制为 尚未认可 的技能。在人类眼中,此类技能显示为 灰色十字 而不是 蓝色十字 如果该技能已经被认可。

您需要 .click() 给定技能的 <a class="endorse-button" role="button" href="javascript:void(0)"> 元素。

你可以通过检查按钮元素(上面提到的)的父元素中是否有"endorsable"来过滤尚未认可的技能有class="endorse-item has-endorsements endorsable"。具体来说:<li class="endorse-item has-endorsements endorsable" data-endorsed-item-name="Molecular Biology">.

字符串"endorsable"是区分未背书和背书的技能,例如,已经背书的技能显示为:<li class="endorse-item has-endorsements endorsed-by-viewer" data-endorsed-item-name="genetics">;而不是 "endorsable" 你有字符串 "endorsed-by-viewer".

过滤后点击认可技能所需代码为:

##############################################################
# Searches for the "endorse skills" buttons and iteratively clicks them...
##############################################################

list_of_skills = browser.find_by_id("profile-skills")[0].find_by_css("li")

for skill in list_of_skills:

    if skill.has_class("endorse-item has-endorsements endorsable"):

        # ...this skill can be endorsed

        button_and_other = skill.find_by_css("div")[0].find_by_css("a") # there are two elements that match "a": [0] list of endorsers, [1] the endorse button

        for css in button_and_other:

            if css.has_class("endorse-button"): # ..if the element has the class: "endorse-button" we click it

                css.click()
    else:

        # ...this skill is already endorsed

        pass