我最近使用 selenium 代碼對我最喜歡的帖子之一發表了評論。一切正常,除非評論寫在文本欄位中,然后必須發布。我該如何解決這個問題?
driver.find_element_by_class_name('Ypffh').click() # click the field to insert comment
field = driver.find_element_by_class_name('Ypffh')
field.clear()
typephrase(comment[counter], field)
sleep(delay)
打擊代碼不適用于發表評論。我該如何解決?
driver.find_element_by_xpath('//button[contains(text(), "Post")]').click() # click the post 'comment' button element
uj5u.com熱心網友回復:
如果這是您嘗試發布的評論,那么我相信您不必單擊發布按鈕,您可以將輸入鍵發送到文本框元素,這將發布評論。這也很有幫助,因為如果他們更改了 post 按鈕元素的 HTML x-path,它仍然可以作業。
這就是我將使用第一部分中的代碼的方式:
from selenium.webdriver.common.keys import Keys
driver.find_element_by_class_name('Ypffh').click() # click the field to insert comment
field = driver.find_element_by_class_name('Ypffh')
field.clear()
typephrase(comment[counter], field)
sleep(delay)
field.send_keys(Keys.ENTER)
希望對您有所幫助,如果沒有,請見諒!
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/439676.html
標籤:javascript Python html 硒 Instagram
