T
T
TechNOIR2017-07-14 16:34:57
Tor
TechNOIR, 2017-07-14 16:34:57

PhantomJS+Selenium+Tor. How to implement this link?

Good afternoon. There are 2 scripts, but I would like to combine them to implement the above bundle...
1. PhantomJS script
The simplest script for checking the IP address

import requesocks
from selenium import webdriver
browser = webdriver.PhantomJS()
browser.get('http://check-host.net/ip')
browser.get_screenshot_as_file('res2.png')
browser.quit()

2. Script for forwarding through Tor proxy. Forwards and issues a new IP address through IP verification
import requesocks
from stem import Signal
from stem.control import Controller
session = requesocks.session()
session.proxies = {'http': 'socks5://127.0.0.1:9150',
'https': 'socks5://127.0.0.1:9150'}
with Controller.from_port(port = 9151) as controller:
        controller.authenticate(password="password")
        controller.signal(Signal.NEWNYM)
print session.get("http://httpbin.org/ip").text

As a result, you need to get PhantomJS to go through the Tor proxy and get a new IP.
Can you please tell me how to build it based on these scripts?
thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Dubrovin, 2017-07-14
@TechNOIR

service_args = [
    '--proxy=127.0.0.1:9150',
    '--proxy-type=socks5',
    ]
browser = webdriver.PhantomJS(service_args=service_args)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question