T
T
TechNOIR2017-01-17 08:15:31
Python
TechNOIR, 2017-01-17 08:15:31

How to run Python+PhantomJS+Selenium through proxy list?

Good day gentlemen!
In general, there is a code:

from selenium import webdriver
browser=webdriver.PhantomJS()
service_args = [
    '--proxy=10.10.20.20:3128',
    '--proxy-type=http',
    ]
browser = webdriver.PhantomJS(service_args=service_args)
browser.get('http://check-host.net/ip')
browser.quit()

Accordingly, changing the proxy and its type in the script - everything works.
But I want to implement so that the values ​​​​in the proxy change from a text file in which proxies follow one after another.
The list of proxies is loaded and a script is executed for each.
How can this be implemented? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
qlkvg, 2017-01-17
@TechNOIR

with open('filename', 'r') as file:
    proxy_list = file.readlines()
for proxy in proxy_list:
    service_args = [
        '--proxy={}'.format(proxy),
        '--proxy-type=http',
        ]

Depending on what is written in the file, you may need to format the lines. If you want everything to be done in parallel, you also need to fasten multiprocessing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question