且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用python硒在***注释中单击链接

更新时间:2023-11-21 18:11:52

要在https://julissars.itworks.com 的所需注释,://www.***.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