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

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

问题描述

我正在使用 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


示例

from selenium import webdriver选项 = webdriver.ChromeOptions()options.add_argument(开始最大化")options.add_argument('--disable-blink-features=AutomationControlled')driver = webdriver.Chrome(options=options, executable_path=r'C:WebDriverschromedriver.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:WebDriverschromedriver.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:WebDriverschromedriver.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")

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

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