硒无法打开第二页 [英] Selenium can't open a second page

查看:75
本文介绍了硒无法打开第二页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium打开网站的不同页面.已经尝试了多次,但是在最初的GET调用之后,浏览器无法打开第二个网页.在Chrome和Safari上都尝试过.这是我的代码:

  driver = webdriver.Chrome()driver.get("https://www.justdial.com/Chennai/Hr-Consultancy-Services/nct-10258625/page-2")driver.set_page_load_timeout(30)driver.get("https://www.justdial.com/Chennai/Hr-Consultancy-Services/nct-10258625/page-3") 

这是我第二个电话遇到的错误:

来自网络日志的信息是错误504,但我已经验证了它在浏览器的另一个窗口上完成时可以完美地工作,而无需自动化

解决方案

有关用例的更多信息将有助于构造更规范的答案.但是,我能够访问,并显示以下错误:

 处理您的请求时发生错误.参考#97.e5732c31.1612205693.6fd2708 


解决方案

为避免被检测,您可以添加以下选项:

 -disable-blink-features = AutomationControlled 


示例

从硒导入Webdriver的

 选项= webdriver.ChromeOptions()options.add_argument(开始最大化")options.add_argument('-disable-blink-features = AutomationControlled')driver = webdriver.Chrome(options = options,execute_path = r'C:\ WebDrivers \ chromedriver.exe')driver.get("https://www.justdial.com/Chennai/Hr-Consultancy-Services/nct-10258625/page-2")driver.get("https://www.justdial.com/Chennai/Hr-Consultancy-Services/nct-10258625/page-3") 

I am using Selenium to open different pages of a site. Have tried multiple times but the browser does not open a second webpage after the initial GET call. Have tried on both Chrome and Safari. Here is my code:

driver = webdriver.Chrome()
driver.get("https://www.justdial.com/Chennai/Hr-Consultancy-Services/nct-10258625/page-2")
driver.set_page_load_timeout(30)
driver.get("https://www.justdial.com/Chennai/Hr-Consultancy-Services/nct-10258625/page-3")

Here is the error I get for the second call:

The info from Network logs is Error 504, but I have verified that it works perfectly when done on another window of the browser, without automation

解决方案

A bit of more information about your usecase would have helped to construct a more canonical answer. However I was able to access the Page 2 of justdial.com/Chennai/Hr-Consultancy-Services with a minimized code block as follows:

  • Code Block:

    from selenium import webdriver
    
    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
    driver.get("https://www.justdial.com/Chennai/Hr-Consultancy-Services/nct-10258625/page-2")
    

  • Browser Snapshot:

But while sending multiple get() one after another:

driver.get("https://www.justdial.com/Chennai/Hr-Consultancy-Services/nct-10258625/page-2")
driver.get("https://www.justdial.com/Chennai/Hr-Consultancy-Services/nct-10258625/page-3")

It seems ChromeDriver initiated Chrome Browser gets detected and the following error is shown:

An error occurred while processing your request.
Reference #97.e5732c31.1612205693.6fd2708


Solution

To avoid the detection you can add the following option:

--disable-blink-features=AutomationControlled


Example

from selenium import webdriver

options = webdriver.ChromeOptions() 
options.add_argument("start-maximized")
options.add_argument('--disable-blink-features=AutomationControlled')
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.justdial.com/Chennai/Hr-Consultancy-Services/nct-10258625/page-2")
driver.get("https://www.justdial.com/Chennai/Hr-Consultancy-Services/nct-10258625/page-3")

这篇关于硒无法打开第二页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆