0

I've written a script in python in combination with selenium to fetch a text block from a webpage in which it is written that my scraper is sending request via proxy or not.

For example: if the request is not sent via proxy then text should appear in the console is like 'This request appears NOT to have come via a proxy.', 'The request appears to have originated from ip address [my_ip_address]' which is what I'm having.

How can I run my scraper through proxy? Thanks in advance.

Script I've tried with:

from selenium import webdriver

proxies = {
    'http': 'http://163.172.27.213:3128',
    'https': 'https://163.172.175.210:3128'
}

chrome_options = webdriver.ChromeOptions()
proxy_arg = ';'.join(['{}={}'.format(k, v) for k, v in proxies.items()])
chrome_options.add_argument('--proxy-server="{}"'.format(proxy_arg))

driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('http://www.lagado.com/proxy-test')
items = [item.text for item in driver.find_elements_by_css_selector(".main-panel p")[:2]]
print(items)
driver.quit()

1 Answer 1

2
from selenium import webdriver

proxy = "12.12.12.12:1212" # IP:PORT or HOST:PORT

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % proxy)

chrome = webdriver.Chrome(chrome_options=chrome_options)
chrome.get("http://www.google.com")
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.