0

How can i use proxy in the python script, not the javascript but the python script?

I have this script:

import time

from selenium import webdriver

from selenium.webdriver.common.keys import Keys
print time.ctime()

service_args = [
    '--proxy=127.0.0.1:1080',
    '--proxy-type=socks5',
    ]
driver = webdriver.PhantomJS('C:\\projects\\phantomjs',service_args=service_args)

driver.set_window_size(1366, 768)

driver.get("http://www.google.com/ncr")
driver.find_element_by_name("q").send_keys("pycon")
driver.find_element_by_xpath("//html/body/center/form/table/tbody/tr/td[2]/span[1]/span/input").click()
html_source = driver.page_source
#print html_source
if "Gmail" in html_source:
    print "Gmail string in source"
else:
    print "Gmail string not in source"
driver.save_screenshot('out.png')
driver.quit()
print time.ctime()

I know how to use a proxy in the javascript file, but this case doesn't contains any javascript file. Is there another way to use proxy?

user215379
  • 127
  • 4
  • 11

0 Answers0