我一直在用Chromedriver测试Selenium,我注意到有些页面可以检测到你正在使用Selenium,即使根本没有自动化.即使我只是通过Selenium和Xephyr使用chrome手动浏览我经常会得到一个页面,说明检测到可疑活动.我检查了我的用户代理和浏览器指纹,它们与普通的Chrome浏览器完全相同.
当我在普通镀铬中浏览这些网站时,一切正常,但是当我使用Selenium的时候,我已经检测到了.
从理论上讲,chromedriver和chrome应该看起来与任何网络服务器完全相同,但不知怎的,他们可以检测到它.
如果你想要一些测试代码试试这个:
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=1, size=(1600, 902))
display.start()
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-extensions')
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--disable-plugins-discovery");
chrome_options.add_argument("--start-maximized")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.delete_all_cookies()
driver.set_window_size(800,800)
driver.set_window_position(0,0)
print 'arguments done'
driver.get('http://stubhub.com')
Run Code Online (Sandbox Code Playgroud)
如果您浏览stubhub,您将在一两个请求中被重定向和"阻止".我一直在研究这个,我无法弄清楚他们如何判断用户是否正在使用Selenium.
他们是如何做到的呢?
编辑更新:
我在Firefox中安装了Selenium IDE插件,当我在普通的firefox浏览器中使用附加插件访问stubhub.com时,我被禁止了.
编辑:
当我使用Fiddler来查看来回发送的HTTP请求时,我注意到"假浏览器"的请求通常在响应头中有"无缓存".
编辑:
这样的结果是否有办法检测到我在Javascript的Selenium Webdriver页面中建议无法检测何时使用webdriver.但是这个证据表明不然.
编辑:
该网站将指纹上传到他们的服务器,但我检查了使用chrome时硒的指纹与指纹相同.
编辑:
这是他们发送到服务器的指纹有效负载之一
{"appName":"Netscape","platform":"Linuxx86_64","cookies":1,"syslang":"en-US","userlang":"en-US","cpu":"","productSub":"20030107","setTimeout":1,"setInterval":1,"plugins":{"0":"ChromePDFViewer","1":"ShockwaveFlash","2":"WidevineContentDecryptionModule","3":"NativeClient","4":"ChromePDFViewer"},"mimeTypes":{"0":"application/pdf","1":"ShockwaveFlashapplication/x-shockwave-flash","2":"FutureSplashPlayerapplication/futuresplash","3":"WidevineContentDecryptionModuleapplication/x-ppapi-widevine-cdm","4":"NativeClientExecutableapplication/x-nacl","5":"PortableNativeClientExecutableapplication/x-pnacl","6":"PortableDocumentFormatapplication/x-google-chrome-pdf"},"screen":{"width":1600,"height":900,"colorDepth":24},"fonts":{"0":"monospace","1":"DejaVuSerif","2":"Georgia","3":"DejaVuSans","4":"TrebuchetMS","5":"Verdana","6":"AndaleMono","7":"DejaVuSansMono","8":"LiberationMono","9":"NimbusMonoL","10":"CourierNew","11":"Courier"}}
Run Code Online (Sandbox Code Playgroud)
它的硒和铬相同
编辑:
VPN仅供一次使用,但在加载第一页后会被检测到.很明显,正在运行一些javascript来检测Selenium.
javascript python selenium google-chrome selenium-chromedriver
有没有办法使用geckodriver使您的 Selenium 脚本在 Python 中无法检测到?
我正在使用 Selenium 进行抓取。我们是否需要使用任何保护措施使网站无法检测到 Selenium?
我正在尝试在 Tor 上运行我的 selenium 驱动程序。请注意,该脚本在没有 Tor 的情况下已经运行且没有错误。
这是我到目前为止所做的:
1)我调用了 Tor 框架
import socks
import socket
from stem.util import term
import stem.process
SOCKS_PORT=7000
socks.setdefaultproxy(proxy_type=socks.PROXY_TYPE_SOCKS5,
addr = "127.0.0.1",
port = SOCKS_PORT)
socket.socket = socks.socksocket
# Perform DNS resolution through the socket
def getaddrinfo(*args): return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (args[0], args[1]))]
socket.getaddrinfo = getaddrinfo
def print_bootstrap_lines(line):
if "Bootstrapped " in line:
print(term.format(line, term.Color.GREEN))
tor_process = stem.process.launch_tor_with_config(
tor_cmd = "C:/Users/my-username\Desktop/Tor Browser/Browser/TorBrowser/Tor//tor.exe" ,
config = { 'SocksPort': str(SOCKS_PORT),},
init_msg_handler = print_bootstrap_lines,
)
Run Code Online (Sandbox Code Playgroud)
在调用了我理解的容器的 Tor 框架之后,我调用了 …
我无法在 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
我经常更新Firefox和Chrome浏览器,当前版本54.0.1 32位所以要使用哪个版本的Geckodriver.我试过两个版本Geckodriver-v0.18.0 and geckodriver-v0.16.1
为了将来参考,我在哪里可以找到支持的firefox浏览器列表以及各自的geckodriver版本
注意:启动浏览器中没有任何代码更改
以前的代码是使用geckodriver-v0.16.1为较旧的firefox版本现在在更新firefox 54.0.1和Geckodriver-v0.18.0后获得异常:
org.openqa.selenium.firefox.NotConnectedException:45000 ms后无法在端口7055上连接到主机127.0.0.1.Firefox控制台输出:oundUpdates":1,"bootstrap":false,"skinnable":false,"size":3242616,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":true "hasBinaryComponents":假 "strictCompatibility":假, "区域设置":[], "targetApplications":[{ "ID": "{ec8030f7-C20A-464f-9b0e-13a3a9e97384}", "MINVERSION":"1.5 ", "MAXVERSION": "9.9"}], "targetPlatforms":[], "multiprocessCompatible":假 "signedState":0, "看到":真 "依赖性":[], "hasEmbeddedWebExtension":假, "mpcOptedOut":假的, "userPermissions":空}
firefox selenium selenium-firefoxdriver selenium-webdriver geckodriver
什么是硒?
当您打开Selenium的官方页面时,您首先读到的是“什么是Selenium?”中的“ Selenium automates browser”。部分。“硒的哪个部分适合我?”部分 下面提供了Selenium WebDriver和Selenium IDE之间的选择。据此,我推断出Selenium是工具的集合,该集合包括IDE,WebDriver API(语言绑定),Grid,Selenium Standalone Server,浏览器驱动程序。必须下载适当的文件才能构建项目。
什么是WebDriver?
WebDriver是一个API。它用多种语言编写,这些语言称为语言绑定。API具有控制浏览器的功能。您可以使用这些功能编写脚本来以所需的方式(测试用例)控制浏览器。
这就是我所知道的。如果我错了,请纠正我。我想从面试的角度知道这两个问题的答案。
我正在尝试连接到Tor浏览器,但收到一条错误消息,指出“ proxyConnectFailure”,我尝试了多次尝试以了解Tor浏览器的基础知识以实现连接的任何想法,但如果有什么话可以挽救生命,那一切都是徒劳的:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary(r"C:\Users\Admin\Desktop\Tor Browser\Browser\firefox.exe")
profile = FirefoxProfile(r"C:\Users\Admin\Desktop\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default")
# Configured profile settings.
proxyIP = "127.0.0.1"
proxyPort = 9150
proxy_settings = {"network.proxy.type":1,
"network.proxy.socks": proxyIP,
"network.proxy.socks_port": proxyPort,
"network.proxy.socks_remote_dns": True,
}
driver = webdriver.Firefox(firefox_binary=binary,proxy=proxy_settings)
def interactWithSite(driver):
driver.get("https://www.google.com")
driver.save_screenshot("screenshot.png")
interactWithSite(driver)
Run Code Online (Sandbox Code Playgroud) 如果我们创建:
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 ×8
firefox ×3
geckodriver ×3
python ×3
java ×2
proxy ×2
tor ×2
webdriver ×2
javascript ×1
python-3.x ×1