我一直在用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
如何使用 Selenium 和 Python 绕过 Google CAPTCHA?
当我尝试抓取某些东西时,Google 会给我一个 CAPTCHA。我可以使用 Selenium Python 绕过 Google CAPTCHA 吗?
例如,它是 Google reCAPTCHA。您可以通过此链接查看此 CAPTCHA:https : //www.google.com/recaptcha/api2/demo
我正在尝试让 Python Selenium 在我的 Windows 机器上工作。我已升级到最新版本的 Firefox、Selenium、Geckodriver,但仍然收到以下错误:
Python脚本
from selenium import webdriver
driver = webdriver.Firefox()
Run Code Online (Sandbox Code Playgroud)
错误
Traceback (most recent call last):
File "run.py", line 17605, in <module>
File "<string>", line 21, in <module>
File "site-packages\selenium\webdriver\firefox\webdriver.py", line 77, in __init__
File "site-packages\selenium\webdriver\firefox\extension_connection.py", line 49, in __init__
File "site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
File "site-packages\selenium\webdriver\firefox\firefox_binary.py", line 103, in _wait_until_connectable
WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.
Run Code Online (Sandbox Code Playgroud)
我还尝试使用以下代码创建 …
add_cookie()在对域stackoverflow.comget()上的页面进行实际请求之前,是否可以在 Selenium Chrome WebDriver 中添加用于域的 cookie,例如stackoverflow.com?
尝试时:
driver.webdriver.add_cookie({'name' : 'testcookie', 'value' : 'testvalue', 'domain' : 'stackoverflow.com'})
driver.webdriver.get('https://stackoverflow.com/')
Run Code Online (Sandbox Code Playgroud)
我得到“您只能为当前域设置 cookie ”。
我想说我看到并尝试了一些避免问题而不是解决问题的解决方案,例如预先访问域上的 404 页面以在 Selenium 中创建“域槽”,然后再向其添加 cookie,但是虽然这些解决方案允许添加他们仍然需要在未设置任何 cookie 的情况下提出一项额外请求并与网站联系。
在处理 CAPTCHA 系统和一些非常具体的 WAF 时,这是一个问题,这些系统在连续看到一个不带 cookie 的请求,然后又看到另一个带 cookie 的请求时会皱起眉头,而这个请求只能在完成登录过程后才被说出。
由于某些未知原因,我的浏览器非常缓慢地打开了远程服务器的测试页。因此,我在考虑是否可以在退出脚本后重新连接到浏览器,但不执行webdriver.quit()此操作将使浏览器保持打开状态。这可能是HOOK或Webdriver句柄。我查找了硒API文档,但未找到任何功能。我正在使用Chrome 62,x64,Windows 7,硒3.8.0。能否解决这个问题,我将不胜感激。
我一直在写的剧本一直工作得很好。我刚刚添加了该选项,因此它将使用此代码在 chrome 上打开一个配置文件。
options = webdriver.ChromeOptions
browser = webdriver.Chrome(executable_path=r"C:\Users\princess\AppData\Local\Programs\Python\Python36-32\chromedriver.exe", chrome_options=options)
options.add_argument(r'user-data-dir=C:\Users\princess\AppData\Local\Google\Chrome\User Data')
options.add_argument('--profile-directory=Profile 1')
Run Code Online (Sandbox Code Playgroud)
使用时,我收到此错误代码。
C:\Users\Princess\Desktop>CHBO.py
Traceback (most recent call last):
File "C:\Users\Princess\Desktop\CHBO.py", line 12, in <module>
browser = webdriver.Chrome(executable_path=r"C:\Users\princess\AppData\Local\Programs\Python\Python36-32\chromedriver.exe", chrome_options=options)
File "C:\Users\Princess\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 59, in __init__
desired_capabilities = options.to_capabilities()
TypeError: to_capabilities() missing 1 required positional argument: 'self'
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
python selenium google-chrome selenium-chromedriver chrome-profile
我正在使用Geckodriver运行最新版本的Selenium WebDriver。我想阻止Selenium在启动WebDriver的新实例时在临时文件目录中创建临时 Firefox 配置文件。相反,我想直接使用原始的 Firefox 配置文件。这有双重好处。首先,它节省了时间(将配置文件复制到临时目录需要花费大量时间)。其次,它确保在会话期间创建的 cookie 保存到原始配置文件中。之前硒开始依赖Geckodriver我能解决这个问题,通过编辑类中,如下图所示:FirefoxProfile.classSeleniumHQ
public File layoutOnDisk() {
File profileDir;
if (this.disableTempProfileCreation) {
profileDir = this.model;
return profileDir;
} else {
try {
profileDir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("ABC", "XYZ");
File userPrefs = new File(profileDir, "user.js");
this.copyModel(this.model, profileDir);
this.installExtensions(profileDir);
this.deleteLockFiles(profileDir);
this.deleteExtensionsCacheIfItExists(profileDir);
this.updateUserPrefs(userPrefs);
return profileDir;
} catch (IOException var3) {
throw new UnableToCreateProfileException(var3);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当参数disableTempProfileCreation设置为 true时,这将阻止 Selenium 创建临时 Firefox 配置文件。
但是,现在 Selenium …
我想要做的是打开一个页面(例如youtube)并自动登录,就像我在浏览器中手动打开它一样。
据我了解,我必须使用cookie,问题是我不知道如何使用。
我尝试使用以下方法下载YouTube Cookie:
driver = webdriver.Firefox(executable_path="driver/geckodriver.exe")
driver.get("https://www.youtube.com/")
print(driver.get_cookies())
Run Code Online (Sandbox Code Playgroud)
我得到的是:
{'name':'VISITOR_INFO1_LIVE','value':'EDkAwwhbDKQ','path':'/','domain':'.youtube.com','expiry':None,'secure':False,'httpOnly ':真实}
那我必须加载什么cookie才能自动登录?
我正在尝试使用 Python 的Selenium Webdriver以及Firefox位于<PROFILE-DIR>.
我尝试过的
#!/usr/bin/env python
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver import Firefox, DesiredCapabilities
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
options = Options()
options.profile = '<PROFILE_DIR>'
webdriver = Firefox(options=options)
Run Code Online (Sandbox Code Playgroud)
这会将现有配置文件复制到临时位置。我可以看到它有效,因为我启动的新会话可以访问配置文件的旧cookie等。但这不是我想要的:我想就地使用配置文件。
capabilities = DesiredCapabilities.FIREFOX.copy()
capabilities['args'] = '--profile <PROFILE-DIR>'
webdriver = Firefox(desired_capabilities=capabilities)
Run Code Online (Sandbox Code Playgroud)
什么也没做:关闭会话后查看geckodriver.log仍然显示类似的内容Running command: "/usr/bin/firefox" "--marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileOFKY46",即仍在使用临时配置文件(它甚至不是 …
我可以使用 Chrome 驱动程序执行以下操作:
b = Watir::Browser.new :chrome, :switches => ['--user-data-dir=C:/some_folder/'] # same philosophy for selenium, just a bit of a different syntax.
Run Code Online (Sandbox Code Playgroud)
这将创建一个新的用户数据目录,其中将存储所有 cookie、书签、缓存等。基本上,创建一个新的配置文件。如果这样的文件夹不存在,它将创建它。如果它确实存在,它将从中加载cookies/所有相关文件。
有没有办法使用 Firefox 驱动程序来做同样的事情?我一直在研究创建 Firefox 配置文件的方法,我发现的只是这篇文章:创建新的 Firefox 配置文件,它不能解决我的问题,因为我希望自动完成它,就像上面的 Chrome 驱动程序一样。另外,您似乎可以使用以下命令创建新的配置文件:
profile = Selenium::WebDriver::Firefox::Profile.new
Run Code Online (Sandbox Code Playgroud)
但我还没有找到用我指定的名称保存该配置文件的方法。
selenium ×9
python ×6
firefox ×3
python-3.x ×2
webdriver ×2
captcha ×1
cookies ×1
geckodriver ×1
java ×1
javascript ×1
recaptcha ×1
ruby ×1
session ×1