如何使用python中的硒单击Instagram评论按钮

发布于 2025-01-17 19:59:08 字数 598 浏览 2 评论 0 原文

我基本上是在试图写一个机器人,该机器人会评论我时间表的最新帖子。 我有使用硒来查找评论按钮的问题。 我尝试了各种寻找它的方法,但仍然没有成功。

HTML:

<svg aria-label="Kommentar" class="_8-yf5 " color="#262626" fill="#262626" height="24" role="img" viewBox="0 0 24 24" width="24"><path d="M20.656 17.008a9.993 9.993 0 10-3.59 3.615L22 22z" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="2"></path></svg>

代码试验:

driver.find_element_by_xpath('/html/body/div\[5\]/div\[2\]/div/article/div\[3\]/section\[3\]/div/form/textarea').click()

有人可以在这里帮助我吗?

I'm basically trying to write a bot which comments on the most recent post of my timeline.
I have issues with finding the comment button using selenium.
I have tried every way of finding it but still didnt succeed.

HTML:

<svg aria-label="Kommentar" class="_8-yf5 " color="#262626" fill="#262626" height="24" role="img" viewBox="0 0 24 24" width="24"><path d="M20.656 17.008a9.993 9.993 0 10-3.59 3.615L22 22z" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="2"></path></svg>

Code trials:

driver.find_element_by_xpath('/html/body/div\[5\]/div\[2\]/div/article/div\[3\]/section\[3\]/div/form/textarea').click()

Anyone can help me here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

平定天下 2025-01-24 19:59:08

单击注释按钮 kommentar webdriverwait element_to_be_clickable() 您可以使用以下任何一个 em>

  • 使用 css_selector

      webdriverwait(驱动程序,20).ultil(ec.element_to_be_be_clickable(((by.css_selector),“ svg [aria-label ='kommentar']))。
     
  • 使用 xpath

      webdriverwait(驱动程序,20).until(ec.element_to_be_be_clickable(((by.xpath,“ //”,“ //*[name()='svg'和 @aria-label ='kommentar']”))))))))))))))))))))) 。点击()
     
  • 注意:您必须添加以下导入:

     来自selenium.webdriver.support.ui导入webdriverwait
    从selenium.webdriver.common.通过进口
    从selenium.webdriver.support进口预期_conditions作为ec
     

The click on the Comment button Kommentar within Instagram you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "svg[aria-label='Kommentar']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[name()='svg' and @aria-label='Kommentar']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
分开我的手 2025-01-24 19:59:08

只需使用 ENTER 方法:

from selenium.webdriver.common.keys import Keys

addComment = find_element_by_xpath('/html/body/div\[5\]/div\[2\]/div/article/div\[3\]/section\[3\]/div/form/textarea')

addComment.send_keys(Keys.ENTER)

Just use ENTER method:

from selenium.webdriver.common.keys import Keys

addComment = find_element_by_xpath('/html/body/div\[5\]/div\[2\]/div/article/div\[3\]/section\[3\]/div/form/textarea')

addComment.send_keys(Keys.ENTER)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文