简体   繁体   English

Python/Selenium:“无法访问此站点”导致“未知错误:无法确定加载状态”

[英]Python/Selenium: "This site can't be reached" caused "unknown error: cannot determine loading status"

I'm running a script that works well to scrape some data I need.我正在运行一个脚本,可以很好地抓取我需要的一些数据。 The script crawl some existing URLs on a given web page and visit each URL to get the final URL.该脚本抓取给定网页上的一些现有 URL 并访问每个 URL 以获取最终 URL。 The problem occurs when the final URL is not found " This site can't be reached ".当最终 URL 未找到“无法访问此站点”时,就会出现问题。 The code crashes and I get this in the log:代码崩溃了,我在日志中得到了这个:

    selenium.common.exceptions.WebDriverException: Message: unknown error: session deleted because of page crash
    from unknown error: cannot determine loading status
    from tab crashed
    (Session info: chrome=84.0.4147.135)
    (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 6.1.7601 SP1 x86_64)

Here is the code I use to scrape the final URLs:这是我用来抓取最终 URL 的代码:

    #Open link (opens in new tab)
    elem = driver.find_element_by_xpath('//*[@id="popup__teaser"]/div[6]/div/div/a')
    elem.click()
    time.sleep(2)

    #wait for redirection to load - switch to the new tab - grab and print the new URL
    driver.get(driver.current_url)
    time.sleep(1)
    driver.switch_to_window(driver.window_handles[1])
    URL= driver.current_url

    #Close active tab 
    driver.close()

    #switch to main tab
    driver.switch_to_window(driver.window_handles[0])

Can anybody help with this issue?有人可以帮忙解决这个问题吗? It only happens when the redirection URL is not found.只有在找不到重定向 URL 时才会发生这种情况。 Thanks谢谢

EDIT: I've tried adding chrome_options.add_argument('--disable-dev-shm-usage') but it didn't work.编辑:我尝试添加chrome_options.add_argument('--disable-dev-shm-usage')但它没有用。

EDIT2: Here is the URL causing the crash EDIT2: 这是导致崩溃的 URL

Try importing requests and check the status code of the site.尝试导入请求并检查站点的状态代码。 For a site to be active, it should normally have a status code of 200. If it does not have a status code of 200 then chances are it cannot be reached要使站点处于活动状态,它的状态代码通常应为 200。如果它没有状态代码 200,则可能无法访问它

import requests

if requests.get(url).status_code!=200:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 selenium / seleniumwire 未知错误:无法从未知错误中确定加载状态:意外的命令响应 - selenium / seleniumwire unknown error: cannot determine loading status from unknown error: unexpected command response 由于未知错误导致页面崩溃,Python Selenium 会话被删除:无法从选项卡崩溃中确定加载状态 - Python Selenium session deleted because of page crash from unknown error: cannot determine loading status from tab crashed 我怎样才能解决python说'WebDriverException :: unknown error'的问题:无法从没有这样的执行上下文确定加载状态? - How can I solve a problem that python says 'WebDriverException:: unknown error: cannot determine loading status from no such execution context? Selenium WebDriverException:消息:未知错误:无法从未知错误确定加载状态:缺少或无效的“entry.level” - Selenium WebDriverException: Message: unknown error: cannot determine loading status from unknown error: missing or invalid 'entry.level' 未知错误:session 由于未知错误导致页面崩溃而被删除:无法从 ChromeDriver 崩溃的选项卡中确定加载状态 Selenium - unknown error: session deleted because of page crash from unknown error: cannot determine loading status from tab crashed with ChromeDriver Selenium Python 中带有 Chrome 的 Selenium Webdriver 问题:回溯错误和无法确定加载状态 - Selenium Webdriver Issue w/ Chrome in Python: Traceback Errors & Can't Determine Loading Status 重定向后出错 - “无法确定加载状态” - Error after redirection - "cannot determine loading status" 无法访问此站点 [flask, python] - This site can’t be reached [flask, python] Selenium chromedriver 2.25 TimeoutException无法确定加载状态 - Selenium chromedriver 2.25 TimeoutException cannot determine loading status 在本地运行 Dash 应用程序时出错,“无法访问此站点” - Error while running Dash app locally, "This site can’t be reached"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM