<a class="yt-simple-endpoint style-scope yt-formatted-string" spellcheck="false" href="/redirect?redir_token=ix1uBK3TO3bxXdcT7EvDFp-vI9p8MTU0NjQxNTExOEAxNTQ2MzI4NzE4&event=comments&q=https%3A%2F%2Fjulissars.itworks.com%2F&stzid=Ugw6ip_QkzwyJPIq3bp4AaABAg" rel="nofollow">https://julissars.itworks.com</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
driver = webdriver.Firefox()
driver.get("https://www.youtube.com/watch?v=UJezMYvf8Ss&lc=Ugw6ip_QkzwyJPIq3bp4AaABAg")
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 import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent
useragent = UserAgent()
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", useragent.random)
driver = webdriver.Firefox(firefox_profile=profile)
driver.get("https://www.youtube.com/watch?v=UJezMYvf8Ss&lc=Ugw6ip_QkzwyJPIq3bp4AaABAg")
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()
要在url中单击所需的注释,文本为https://julissars.itworks.com,您需要引导WebDriverwait以使元素可单击,您可以通过Selenium和Python使用useragent使用以下解决方案:
>
代码块:
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, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get("https://www.youtube.com/watch?v=UJezMYvf8Ss&lc=Ugw6ip_QkzwyJPIq3bp4AaABAg")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='yt-uix-sessionlink ' and contains(@href, 'julissars')]"))).click()
控制台输出:
Mozilla/5.0 (X11; NetBSD) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
问题内容: 在程序中使用用户身份验证的代理的最佳/最简便方法是什么?我目前有这个,但是打开浏览器时我需要输入用户名和密码。 问题答案: 您可以使用Proxy Auto auth插件实现相同的功能 使用以下扩展程序下载扩展程序 https://chrome.google.com/webstore/detail/get- crx/dijpllakibenlejkbajahncialkbdkjc/rel
以下是我试图单击的按钮的HTML代码: 我可以使用XPath/Class Name/CSS选择器点击按钮的可能方式有哪些? 我做了如下尝试:
这里是我的错误:
我的目标是使用selenium python来点击这个超链接元素,下面是我尝试过的3个解决方案,没有一个有效。 解决方案1: 错误消息:selenium.common.exceptions.javascriptException:消息:javascript错误:无法读取未定义的属性“click” 那么,每个解决方案都出了什么问题呢?我怎么才能让它起作用?
我有一个带有几个矩形元素的对象。使用,我试图点击一个主要的对象。然而,使用xpath检查器,我无法检测到相同的。 到目前为止,我能够深入到直到: 我的代码如下: 有人能帮我吗?
问题内容: 我正在使用Python中的Selenium进行网站抓取项目。当我通过浏览器打开主页时,它会正确打开。 但是,当我尝试通过Selenium 打开网页时,它会打开一个完全不同的页面。 我认为,它能够检测(不确定被称为什么)并能够检查浏览器的属性或其他内容。 是否可以通过传递属性,以便加载正确的首页。 谢谢 问题答案: 通过更改浏览器的配置文件,可以在python版本的webdriver中更