1

I am trying to take a screenshot of a website, but it is not developed. Selenium returns me the following message:

selenium.common.exceptions.WebDriverException: 
Message: Reached error page: about:neterror?e=dnsNotFound&u=https%3A//test-test-test-test-test.info/&c=UTF-8&d=We%20can%E2%80%99t%20connect%20to%20the%20server%20at%20test-test-test-test-test.info.

I use the method:

driver.save_screenshot("my_pic.png")

Is there a way, I would get an image, despite DNS is not being found?

filtertips
  • 801
  • 3
  • 12
  • 25
  • 1
    Not Sure what images you are after. However since you are getting exception before capturing the screenshot. Use `try..except` block and capture screenshot in the `except` block using the same code. Hope this will help. – KunduK Dec 10 '20 at 16:22
  • 2
    I don't think this is related to the screenshot at all. I think the error is coming from a driver.get that precedes it. See also https://stackoverflow.com/questions/43812991/selenium-webdriverexception-reached-error-page – DMart Dec 10 '20 at 16:29
  • @KunduK Yes you are correct! – filtertips Dec 10 '20 at 16:45
  • @Dmart Yes, I can't believe how i didn't notice that. – filtertips Dec 10 '20 at 16:46

1 Answers1

0

I had the same problem while scraping data using the Tor network. I got the same exception. Below is the code of the function designed to support the Tor network that caused the problem:

def firefoxdriver(my_url):
    """
    Preparing of the Tor browser for the work and adding the headers 
    to the browser.
    """
    # Preparing of the Tor browser for the work.
    # for my laptop
    # torexe = os.popen(\
    #    r'C:\Users\Oliver\Desktop\Tor Browser\Browser\firefox.exe')
    # for my mainframe
    torexe = os.popen(\
        r'C:\Users\olive\OneDrive\Pulpit\Tor Browser\Browser\firefox.exe')
    # for my laptop
    # profile = FirefoxProfile(\
    #     r'C:\Users\Oliver\Desktop\Tor Browser\Browser\TorBrowser\Data\'+
    #     'Browser\profile.default')
    # for my mainframe
    profile = FirefoxProfile(\
        r'C:\Users\olive\OneDrive\Pulpit\Tor Browser\Browser\TorBrowser\Data'+
            '\Browser\profile.default')
    profile.set_preference('network.proxy.type', 1)
    profile.set_preference('network.proxy.socks', '127.0.0.1')
    profile.set_preference('network.proxy.socks_port', 9150)
    profile.set_preference('network.proxy.socks_remote_dns', False)
    profile.update_preferences()
    firefox_options = Options()
    driver = Firefox(firefox_profile=profile, options=firefox_options)

    # # Adding the headers to the browser.
    _addingheaders(my_url)

In this code, I only replaced the value False with the value True in the code line of this function as follows:

    profile.set_preference('network.proxy.socks_remote_dns', True)

This completely solved the problem.

Olgierd Wiśniewski
  • 433
  • 2
  • 8
  • 14