3

I'm using selenium with Python3. Here's my code:

import socks
import socket
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options


socks.set_default_proxy(socks.SOCKS5, "localhost", 9150)
socket.socket = socks.socksocket

opts = Options()
opts.set_headless()
assert opts.headless
browser = Firefox(options=opts)

browser.get('http://checkip.dyndns.org')
browser.save_screenshot('ip.png')

I receive

selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver

on the line

browser = Firefox(options=opts)

Problem in the following lines:

socks.set_default_proxy(socks.SOCKS5, "localhost", 9150)
socket.socket = socks.socksocket

If I remove them, code work normally. Why does it happens? How should I fix that?

Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
DeadUnicorn
  • 175
  • 1
  • 12
  • see if this helps https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#using-a-proxy & https://stackoverflow.com/questions/17082425/running-selenium-webdriver-with-a-proxy-in-python – Naveen Kumar R B Mar 16 '18 at 14:59
  • I think ` fp.set_preference("network.proxy.socks",PROXY_HOST) fp.set_preference("network.proxy.socks_port",int(PROXY_PORT)) ` lines are missing in your code which links actual proxy settings with firefox browser. please refer to this answer which have socks reference https://stackoverflow.com/a/30567191/2575259 – Naveen Kumar R B Mar 16 '18 at 15:02

0 Answers0