我正在使用python(Linkedin網站)進行一些網頁抓取,並遇到以下兩個問題:1)如何在搜索欄上輸入文本? 2)如何點擊一個按鈕?首先,這是搜索欄代碼:使用Python進行網頁抓取:輸入文本並單擊按鈕
search = driver.find_element_by_xpath('//*[@id="a11y-ember997"]')
search.send_keys('MedMake')
所以可以:
<input aria-autocomplete="list" autocomplete="off" spellcheck="false"
placeholder="Búsqueda" autocorrect="off" autocapitalize="off" id="a11y-
ember6214" role="combobox" class="ember-text-field ember-view" aria-
expanded="false">
要輸入我使用XPath(和它的作品),但它改變了我每次登錄到該網站的時間文本我使用上面的部分輸入條形碼,以便我可以多次重新運行腳本?
我的第二點是2)如何點擊一個按鈕。我再次使用xpath,但每次登錄後都會更改。我的代碼是:
button = driver.find_element_by_xpath('//*[@id="nav-search-controls-wormhole"]/button')
button.click()
我檢查了按鈕的代碼和我反而喜歡用數據垂直=「人」或其他任何這一獨特的領域(的標籤按鈕是不夠的,因爲有很多的按鈕Linkedin網站)。順便說一下,這些內部領域是如何被調用的?我相信我的問題的部分原因是缺乏對html代碼的理解。
<button data-vertical="PEOPLE" data-control-
name="vertical_nav_people_toggle" data-ember-action="" data-ember-
action-8620="8620" data-is-animating-click="true">
Gente
</button>