我正在使用python 3,RotatingProxyBot和fake_useragent。 https://pypi.org/project/RotatingProxyBot/ https://pypi.org/project/fake-useragent/
我想更改每个webdriver硒上的ip和用户代理
请在下面查看我的代码,该代码进行30次循环,并尝试通过打开http://atomurl.net/myip/来显示用户代理和ip
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from RotatingProxyBot import ProxyBot
from fake_useragent import UserAgent
import random
# Create new custom bot
bot = ProxyBot(
desired_reqs=1,
reqs_per_int=2,
wait_time=5 # 1min
)
# Start Submiting and rotating proxies
bot.enable()
i=0
while 1<30:
# We configure user-agent
options = Options()
userAgent = UserAgent()
print("userAgent : " + str(userAgent))
options.add_argument(f'user-agent={userAgent}')
# We open driver and go to Linkedin
driver = webdriver.Chrome(chrome_options=options,
executable_path=r'C:\Users\Nino\Documents\Python37\libs\chromedriver.exe')
driver.implicitly_wait(10)
i+=1
print("i =>" + str(i))
driver.get('http://atomurl.net/myip/')
print("Open page")
time.sleep(3)
bot.preformRotate()
driver.quit()
应该在每个循环上更改用户代理和ip,但atomurl.net/myip/始终显示相同的ip。
我检查了类似的问题,但是他们使用了草率的库房。我想使用这两个库:fake_useragent和RotatingProxyBot。