【问题标题】:How to click a link within youtube comment using python selenium如何使用 python selenium 单击 youtube 评论中的链接
【发布时间】:2018-12-29 09:04:13
【问题描述】:

我是 selenium python 的新手,我正在尝试单击 youtube 评论中的链接,但我不知道要使用什么元素?有人能帮我吗?谢谢 。 示例:

<a class="yt-simple-endpoint style-scope yt-formatted-string" spellcheck="false" href="/redirect?event=comments&amp;redir_token=ttzJJRuKzz6sJPh8qdMnWStc-958MTU0NjE1NDU4M0AxNTQ2MDY4MTgz&amp;stzid=Ugw6ip_QkzwyJPIq3bp4AaABAg&amp;q=https%3A%2F%2Fjulissars.itworks.com%2F" rel="nofollow">https://julissars.itworks.com&#65279;</a> 

link

【问题讨论】:

    标签: python selenium xpath css-selectors webdriverwait


    【解决方案1】:

    要在url 中单击文本为https://julissars.itworks.com 的所需评论,您需要诱导WebDriverwait 以使元素可点击,您可以使用以下解决方案:

    • 使用PARTIAL_LINK_TEXT

      WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "julissars"))).click()
      
    • 使用CSS_SELECTOR

      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.yt-simple-endpoint.style-scope.yt-formatted-string[href*='julissars']"))).click()
      
    • 使用XPATH

      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='yt-simple-endpoint style-scope yt-formatted-string' and contains(., 'julissars')]"))).click()
      
    • 注意:您必须添加以下导入:

      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.common.by import By
      from selenium.webdriver.support import expected_conditions as EC
      

    【讨论】:

    • 你能帮我多一点吗? @DebanjanB
    • @vantuong 随时根据您的新要求提出新问题。 Stackoverflow 贡献者将很乐意为您提供帮助。
    • stackoverflow.com/questions/53993925/… !我在这里创建了一个新问题
    猜你喜欢
    • 1970-01-01
    • 2019-05-28
    • 2020-09-10
    • 1970-01-01
    • 2015-03-31
    • 2014-04-24
    • 2018-02-08
    • 2021-12-03
    • 2020-05-25
    相关资源
    最近更新 更多