0

I'd like to execute the following code using a multithreaded solution

Can anyone suggest how to improve the solution?

from selenium import webdriver

with open('proxy.txt', 'r') as f: 
    for line in f:
        print ("Connected with IP: {}".format(line))
        PROXY = line # IP:PORT or HOST:PORT
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('--proxy-server=http://%s' % PROXY)
        driver = webdriver.Chrome(chrome_options=chrome_options)
        driver.get("http://whatismyipaddress.com")
        driver.quit()
4
  • Please explain more detailed and more deeply what you are trying to archive. Commented Jan 17, 2019 at 22:46
  • @AK47 i try it but i cant achieve my goal. Commented Jan 17, 2019 at 22:50
  • @KlausD. i use this code for visits but i need to make him doing this process on multi threads so it can work faster? i hope im clear Commented Jan 17, 2019 at 22:51
  • @markcontira see my answer Commented Jan 17, 2019 at 22:52

1 Answer 1

3
import os 
from multiprocessing import Pool

from selenium import webdriver

def check_ip(proxy):
    print ("Connected with IP: {}".format(proxy))
    options = webdriver.chrome.options.Options()
    options.add_argument('--proxy-server=http://{}'.format(proxy))
    driver = webdriver.Chrome(options=options)
    driver.get("http://whatismyipaddress.com")
    driver.quit()

if __name__ == '__main__':
    with open('./proxy.txt') as f:
        proxies = f.read().splitlines()
    with Pool() as pool:
        pool.map(check_ip, proxies)

Solution is based on the answer in this question

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.