Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Google阻止Selenium Web驱动程序_Python_Selenium - Fatal编程技术网

Python Google阻止Selenium Web驱动程序

Python Google阻止Selenium Web驱动程序,python,selenium,Python,Selenium,我有一个脚本,我试图通过selenium搜索谷歌页面来测试一些东西。无论何时打开Webdriver,我都会收到一份验证码表单: fp = webdriver.FirefoxProfile() driver = webdriver.Firefox(firefox_profile=fp) driver.get('https://www.google.com/search?q=asdf') 但是,如果我在浏览器中打开完全相同的页面,它工作正常。为什么谷歌会提高验证码,我可以用webdriver发送哪

我有一个脚本,我试图通过
selenium
搜索谷歌页面来测试一些东西。无论何时打开
Webdriver
,我都会收到一份验证码表单:

fp = webdriver.FirefoxProfile()
driver = webdriver.Firefox(firefox_profile=fp)
driver.get('https://www.google.com/search?q=asdf')
但是,如果我在浏览器中打开完全相同的页面,它工作正常。为什么谷歌会提高验证码,我可以用
webdriver
发送哪些参数,使其“看起来”像普通浏览器,而不会提高验证码

注意,我已尝试添加我的用户代理,但仍会引发相同的错误:

fp = webdriver.FirefoxProfile()
fp.set_preference("general.useragent.override","Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:32.0) Gecko/20100101 Firefox/32.0")
driver = webdriver.Firefox(firefox_profile=fp)
以下是来自普通浏览器的“我的请求”标题示例:


您需要设置用户代理。 看到这个了吗


使用
设置\u首选项时

使用请求传递所有标题:

headers = {
    "Host": "www.google.com",
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:32.0) Gecko/20100101 Firefox/32.0",
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    "Accept-Language": "en-US,en;q=0.5",
    "Accept-Encoding": "gzip, deflate",
    "Cookie": "PREF=ID=0df7e6fbda0c09d3:U=bfc47b624b57a0e9:FF=0:TM=1414961297:LM=1414961298:S=2FtJad1BEeJ0M5XS; NID=67=t5zTrFVtG4cLZH2kVmsQEbqDRFJisM86z1s27zx0A6vTR0MWqg69DaY39muso6fIEgqnli7IaEv1Rge1ZxBG0Nr1_3KH1aLu_z1-Ar48oiVDFFSVX4KDRgWnHQWjUfHC",
    "Connection": "keep-alive",
    "Cache-Control": "max-age=0",
}

可能重复“否”,我建议删除上面的“类似问题”,因为这是一个完全不同的问题。@David542,您是否支持某种代理?网络驱动程序向呈现的源添加指纹。例如,firefox驱动程序注入“webdriver=True”。这个问题与发送用户代理无关。请查看修订后的问题。哦,即使通过用户代理,您仍然会收到验证码?您是否尝试过在没有剩余字符串的情况下设置
Mozilla/5.0
?是的,我仍然会收到。这很奇怪,因为我可以用上面完全相同的代码打开驱动程序,这应该是一个答案吗?我建议更详细地说明解决方案是什么,因为这很清楚。