I'm working on python script using selenium to automate some tasks, the issue is that after some requests website block the account, after manual test i found changing proxy and user agent solve the issue, but i can't do it while the browser on the fly, i'm forced to close the browser each N times and re-open it with the new proxy and user-agent.
options = Options()
options.add_argument('log-level=3')
proxy = '96.113.166.133:1080'
options.add_argument('--proxy-server=socks5://' + proxy)
ua = UserAgent()
userAgent = ua.random
options.add_argument(f'user-agent={userAgent}')
driver = webdriver.Chrome(options=options)
driver.get(url)
with open("a.txt", "r") as ins: # check each line in text
try:
for line in ins:
#Do some code
Now the question how can i change the proxy and user-agent after each N times without closing the browser like that ?
options = Options()
options.add_argument('log-level=3')
driver = webdriver.Chrome(options=options)
driver.get(url)
with open("a.txt", "r") as ins: # check each line in text
try:
for line in ins:
proxy = '96.113.166.133:1080'
options.add_argument('--proxy-server=socks5://' + proxy)
ua = UserAgent()
userAgent = ua.random
options.add_argument(f'user-agent={userAgent}')
#Do some code
Thanks