E
E
Emil Revencu2016-09-25 23:40:46
Python
Emil Revencu, 2016-09-25 23:40:46

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

Launched PhantomJS nodes (50 instances):
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"

I checked the server and the nodes if they got up: 127.0.0.1:4444/grid/console
3b2e99d11965470086599798292ef402.png
Run the python code:
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')

It works without problems
But you need to run it through a proxy . I
found it on the net:
driver.command_executor._commands['executePhantomScript'] = ('POST', '/session/$sessionId/phantom/execute')
driver.execute('executePhantomScript', {'script': '''phantom.setProxy("94.20.21.38", 3128);''', 'args' : [] })

Added, but the answer is an error:
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:

What is the problem or how to set proxy for Remote Webdriver PhantomJS?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Emil Revencu, 2016-09-26
@Revencu

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

Question removed. Thanks to all!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question