如何使用 Selenium 和 Python 绕过 Google CAPTCHA?
当我尝试抓取某些东西时,Google 会给我一个 CAPTCHA。我可以使用 Selenium Python 绕过 Google CAPTCHA 吗?
例如,它是 Google reCAPTCHA。您可以通过此链接查看此 CAPTCHA:https : //www.google.com/recaptcha/api2/demo
我正在使用selenium python webdriver来浏览一些页面.我想在加载和执行任何其他Javascript代码之前将javascript代码注入页面.另一方面,我需要将我的JS代码作为该页面的第一个JS代码来执行.有没有办法通过Selenium做到这一点?
我用谷歌搜索了几个小时,但我找不到任何正确的答案!
我在住宅代理网络后面的Ubuntu服务器上通过 Selenium 运行 Chrome 驱动程序。然而,我的硒正在被检测到。有没有办法让 Chrome 驱动程序和 Selenium 100% 无法检测?
我已经尝试了很长时间,但我忘记了我所做的许多事情,包括:
我正在寻找 100% 无法检测到的真正 Selenium 版本。如果那曾经存在过。或者机器人跟踪器无法检测到的另一种自动化方式。
这是浏览器启动的一部分:
sx = random.randint(1000, 1500)
sn = random.randint(3000, 4500)
display = Display(visible=0, size=(sx,sn))
display.start()
randagent = random.randint(0,len(useragents_desktop)-1)
uag = useragents_desktop[randagent]
#this is to prevent ip leaking
preferences =
"webrtc.ip_handling_policy" : "disable_non_proxied_udp",
"webrtc.multiple_routes_enabled": False,
"webrtc.nonproxied_udp_enabled" : False
chrome_options.add_experimental_option("prefs", preferences)
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-impl-side-painting")
chrome_options.add_argument("--disable-setuid-sandbox")
chrome_options.add_argument("--disable-seccomp-filter-sandbox")
chrome_options.add_argument("--disable-breakpad")
chrome_options.add_argument("--disable-client-side-phishing-detection")
chrome_options.add_argument("--disable-cast")
chrome_options.add_argument("--disable-cast-streaming-hw-encoding")
chrome_options.add_argument("--disable-cloud-import")
chrome_options.add_argument("--disable-popup-blocking")
chrome_options.add_argument("--ignore-certificate-errors")
chrome_options.add_argument("--disable-session-crashed-bubble")
chrome_options.add_argument("--disable-ipv6")
chrome_options.add_argument("--allow-http-screen-capture") …Run Code Online (Sandbox Code Playgroud) selenium google-chrome webdriver selenium-chromedriver selenium-webdriver
我试图找出一种方法,每当我在这个特定的脚本中通过Selenium(在Python中)打开Chrome时,Chrome页面会自动打开并选择另一个用户代理 - 在这种情况下,Microsoft Edge Mobile(但我会是从桌面访问它).
因此,在做了一些研究后,我已经能够拼凑出以下代码,我认为这些代码会在Chrome中执行用户代理切换,然后打开一个新的Bing.com页面:
来自selenium import webdriver
来自selenium.webdriver.chrome.options
导入选项opts =选项()
opts.add_argument("user-agent = Mozilla/5.0(Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 640 XL LTE)AppleWebKit/537.36(KHTML,与Gecko一样)Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10166 ")
driver = webdriver.Chrome(chrome_options = opts)
driver = webdriver.Chrome("D:_")
driver.get(" https://www.bing.com/ ")
但是,在打开指定的网页之前,代码似乎没有工作并停止.我很确定上半部分代码是关闭的,但我不太清楚如何.任何和所有的帮助将深表感谢.
我按照Stackoverflow 上的这篇文章禁用了Firefox WebDriver检测。
启动 Geckodriver:
System.setProperty("webdriver.gecko.driver", geckdriverExecutableFilePath);
File firefoxProfileFile = new File(fullPathOfFirefoxInstallationFolder);
FirefoxProfile firefoxProfile = null;
try {
firefoxProfile = new FirefoxProfile(firefoxProfileFile);
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我禁用了WebDriver:
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(firefoxProfile);
// Disables WebRTC
firefoxProfile.setPreference("media.peerconnection.enabled", false);
Run Code Online (Sandbox Code Playgroud)
我禁用了自动化扩展:
// Disables Automation Extension
firefoxProfile.setPreference("useAutomationExtension", false);
Run Code Online (Sandbox Code Playgroud)
我添加了代理:
DesiredCapabilities dc = DesiredCapabilities.firefox();
Proxy proxy = new Proxy();
proxy.setHttpProxy(ipAddress + ":" + port);
proxy.setFtpProxy(ipAddress + ":" + port);
proxy.setSslProxy(ipAddress + ":" + …Run Code Online (Sandbox Code Playgroud) 我无法在 Selenium Webdriver 3 中为 Firefox 设置默认配置文件,因为FirefoxDriver类中没有这样的构造函数。
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.ProfilesIni;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class SeleniumStartTest {
@Test
public void seleniumFirefox() {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\FirefoxDriver\\geckodriver.exe");
ProfilesIni profileIni = new ProfilesIni();
FirefoxProfile profile = profileIni.getProfile("default");
WebDriver driver = new FirefoxDriver(profile);
driver.get("http://www.google.com");
}
}
Run Code Online (Sandbox Code Playgroud)
Java 代码中的编译错误: Java 代码
Mavenpom.xml依赖项:
Selenium 3.14.0
火狐版: 火狐版 62.0.2
我time在我的脚本中使用库:
import time
time.sleep(1)
Run Code Online (Sandbox Code Playgroud)
它可以让我的 Selenium WebDriver 休眠一秒钟,但 250 毫秒怎么可能呢?
我已经尝试了多种解决方案,但是到目前为止还没有任何运气。我正在尝试使用python中的硒访问tor浏览器,但是当我的程序打开Tor时,Tor给我一个错误消息:
Tor failed to start.
Run Code Online (Sandbox Code Playgroud)
然后,Python给出以下错误消息:
selenium.common.exceptions.WebDriverException: Message: permission denied
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
binary = FirefoxBinary(r"C:\\Users\\User\\Desktop\\Tor Browser\\Browser\\firefox.exe")
profile = FirefoxProfile(r"C:\\Users\\User\\Desktop\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default")
driver = webdriver.Firefox(firefox_binary=binary)
driver = webdriver.Firefox(firefox_profile= profile, firefox_binary= binary, executable_path = r"C:\\Users\\User\\Desktop\\geckodriver.exe")
driver.profile.set_preference('network.proxy.type', 1)
driver.profile.set_preference('network.proxy.socks', '127.0.0.1')
driver.profile.set_preference('network.proxy.socks_port', 9150)
profile.set_preference("network.proxy.socks_remote_dns", False)
profile.update_preferences()
driver.get("http://yahoo.com")
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激!
什么是硒?
当您打开Selenium的官方页面时,您首先读到的是“什么是Selenium?”中的“ Selenium automates browser”。部分。“硒的哪个部分适合我?”部分 下面提供了Selenium WebDriver和Selenium IDE之间的选择。据此,我推断出Selenium是工具的集合,该集合包括IDE,WebDriver API(语言绑定),Grid,Selenium Standalone Server,浏览器驱动程序。必须下载适当的文件才能构建项目。
什么是WebDriver?
WebDriver是一个API。它用多种语言编写,这些语言称为语言绑定。API具有控制浏览器的功能。您可以使用这些功能编写脚本来以所需的方式(测试用例)控制浏览器。
这就是我所知道的。如果我错了,请纠正我。我想从面试的角度知道这两个问题的答案。
如果我们创建:
ChromeDriver driver=new ChromeDriver();
Run Code Online (Sandbox Code Playgroud)
chrome 驱动程序方法将被执行。
如果我们创建:
WebDriver driver=new ChromeDriver();
Run Code Online (Sandbox Code Playgroud)
再次ChromeDriver执行方法[根据方法覆盖]。
那为什么我们只在执行时写后一个呢?
java selenium webdriver selenium-webdriver webdriver-w3c-spec
selenium ×11
python ×6
webdriver ×5
geckodriver ×3
java ×3
tor ×2
captcha ×1
firefox ×1
javascript ×1
proxy ×1
recaptcha ×1
user-agent ×1