如何使用python硒在youtube注释中单击链接 [英] How to click a link within youtube comment using python selenium

查看:50
本文介绍了如何使用python硒在youtube注释中单击链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Selenium python的新手,我想单击youtube评论中的链接,但我不知道要使用什么元素?有人能帮我吗?谢谢 .例子:

I'm new to selenium python, I'm trying to click a link in the youtube comment but I don't know what element to use? Can someone help me? thanks . example :

<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> 

链接

推荐答案

要在https://julissars.itworks.com 的所需注释,://www.youtube.com/watch?v = UJezMYvf8Ss& lc = Ugw6ip_QkzwyJPIq3bp4AaABAg"rel =" nofollow noreferrer> url 您需要为元素引入 WebDriverwait 可以点击,您可以使用以下任一解决方案:

To click on the desired comment with text as https://julissars.itworks.com within the url you need to induce WebDriverwait for the element to be clickable and you can use either of the following solution:

  • 使用 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()
    

  • 注意:您必须添加以下导入:

  • 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
    

  • 这篇关于如何使用python硒在youtube注释中单击链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆