Home > OS >  How to modify selenium webdriver dns to custom one
How to modify selenium webdriver dns to custom one

Time:01-15

so for some reason my webdriver session does not able to enter some website that on my normal browser I can, I receive DNS_PROBE_FINISHED_NXDOMAIN error.

I tried manually change the DNS provider to CloudFlare (1.1.1.1)

enter image description here

and then it worked, how can I make the webdriver be loaded with that settings?

I tried the following code snipper

chrome_options = options.Options()
local_state = {
    "dns_over_https.mode": "automatic",
    "dns_over_https.templates": "1.1.1.1",
}
chrome_options.add_experimental_option('localState', local_state)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)

And few more variations, can't find anything on google nor here.

Any help would be appriciated.

CodePudding user response:

Here's an example of how to set the DNS server to 8.8.8.8 for a Chrome webdriver:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--proxy-server=socks5://8.8.8.8:1080")

driver = webdriver.Chrome(chrome_options=chrome_options)

Keep in mind that the exact options you need to set and the way you set them may vary depending on the version of the browser you are using. Also, you should check the DNS you are trying to use, it should be valid and reachable.

  • Related