これまでの研究
splinter のヘルプ ドキュメントを読み、Stack Overflow を検索し、さまざまなアイデアを試すのに約 4 時間を費やしました。失敗。
質問
Linkedin で接続のスキルを自動的に承認し、まだ承認されていないスキルへの相互作用を制限する方法を理解するのに苦労しています。人間の目には、そのようなスキルは、そのスキルがすでに承認されている場合は青い十字ではなく、灰色の十字で示されます。
特定のスキル.click()
の要素を使用する必要があります。<a class="endorse-button" role="button" href="javascript:void(0)">
ボタン要素(上記)の親要素に「承認可能」があるかどうかを確認することで、まだ承認されていないスキルをフィルタリングできますclass="endorse-item has-endorsements endorsable"
。具体的には: <li class="endorse-item has-endorsements endorsable" data-endorsed-item-name="Molecular Biology">
.
「承認可能」という文字列は、承認されていないスキルと承認済みのスキルを区別するものです。たとえば、既に承認されているスキルは次のように表示されます<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