【发布时间】:2019-01-04 10:16:27
【问题描述】:
我正在学习 python selenium,我想点击 youtube 评论中的 youtube 链接,有人可以帮我吗?
示例:URL
HTML:
<a class="yt-simple-endpoint style-scope yt-formatted-string" spellcheck="false" href="/watch?v=PbLtyVcMrk0">https://www.youtube.com/watch?v=PbLtyVcMrk0&#65279;</a>
代码试验:
from selenium import webdriver
from fake_useragent import UserAgent
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
ua = UserAgent()
options = webdriver.ChromeOptions()
userAgent = ua.random
print(userAgent)
options.add_argument('user-agent={userAgent}')
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://www.youtube.com/watch?v=NIWwJbo-9_8&lc=UgwNBxYVXb6uiVTioPB4AaABAg")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='yt-uix-sessionlink ' and contains(@href, '/watch?v=PbLtyVcMrk0')]"))).click()
【问题讨论】:
标签: python selenium youtube user-agent webdriverwait