0

Hi I am fairly new to selenium and I am building a bot that visits a website and enters a term then submits. The issue is that you can only Submit a certain amount of times before the IP address used gets blocked by the server for spam. Is there a way I can implement a proxy rotation every time it opens up a new chrome browser.

Xsnipe
  • 11
  • 4

1 Answers1

-1

It would be important to know which browser you are using because the settings differ a bit from browser to browser.

Here is an example of how to use a proxy with Chrome:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

PROXY = "1.111.111.1:8080" #your proxy

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

chrome = webdriver.Chrome(chrome_options=chrome_options)
chrome.get("yourwebsite.com")
zebo
  • 141
  • 10
  • Thank you but how do I rotate the proxies from a txt file. So that every time the program opens a new chrome window a different proxy is pulled from a text file and then used in chrome. – Xsnipe Jun 07 '20 at 20:19
  • @Xsnipe If your Proxies are seperated by newlines or commas or something similar etc: Check out this site stack overflow article: [link](https://stackoverflow.com/questions/3277503/how-to-read-a-file-line-by-line-into-a-list) and loop through the list using a `for` loop – zebo Jun 07 '20 at 20:37
  • Ok I will thank you – Xsnipe Jun 07 '20 at 22:29
  • 1
    When running the code you entered in I got an error saying "NameError: name 'WebDriverWait' is not defined" – Xsnipe Jun 08 '20 at 01:53
  • Yes, you can either delete the line where it is mentioned because you will probably not need it or import it at the beginning. – zebo Jun 08 '20 at 08:55