Answer the question
In order to leave comments, you need to log in
How to set up PROXY in Python for PhantomJS Node launched via Selenium grid HUB?
Raised Selenium server grid:
java -jar selenium-server-standalone-2.53.1.jar -role hub
java -jar selenium-server-standalone-2.53.1.jar -role webdriver -hub http://localhost:4444/grid/register -browser "browserName=phantomjs, version=ANY, platform=WINDOWS, maxInstances=50, timeout=90000"
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=DesiredCapabilities.PHANTOMJS)
driver.get('http://www.SiteForScrape.com')
driver.command_executor._commands['executePhantomScript'] = ('POST', '/session/$sessionId/phantom/execute')
driver.execute('executePhantomScript', {'script': '''phantom.setProxy("94.20.21.38", 3128);''', 'args' : [] })
selenium.common.exceptions.WebDriverException: Message: POST /session/a95e422b-420d-44c3-b67e-c62e8939ee50/phantom/execute
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'WIN-7VFJU84Р78HI', ip: '192.168.1.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_101'
Driver info: driver.version: unknown
Stacktrace:
Answer the question
In order to leave comments, you need to log in
Pss.... It turned out to be very simple:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
webdriver.DesiredCapabilities.PHANTOMJS['proxy']={"httpProxy":'94.20.21.38:3128', "proxyType":"MANUAL"}
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=DesiredCapabilities.PHANTOMJS)
driver.get('https://www.iplocation.net/')
x=driver.find_element_by_xpath('//p[contains(text(),"Your public IP Address is")]')
if x is not None: print x.text
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question