使用Python中的代理运行Selenium Webdriver不更改IP

发布于 2025-01-29 01:41:53 字数 1345 浏览 3 评论 0 原文

我正在尝试使用硒来制作Python代理,我有一个来自但是我得到的IP总是相同的,此设置有问题吗?

PROXY = proxy_list[11]
options = Options()
options.headless = False

webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
    "httpProxy":PROXY,
    "ftpProxy":PROXY,
    "sslProxy":PROXY,
    "noProxy":None,
    "proxyType":"MANUAL",
    "class":"org.openqa.selenium.Proxy",
    "autodetect":False
}
driver = webdriver.Firefox(options=options, executable_path=r'geckodriver.exe')
# Set the interceptor on the driver
driver.request_interceptor = interceptor 
driver.get(url)
time.sleep(5)
driver.quit()

编辑:我根据响应的响应来运行以下代码:

url = 'https://www.whatismyip.com/es/'
PROXY = proxy_list[6]
options = Options()
options.headless = False

firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['proxy'] = {
    'proxyType': "MANUAL",
    'httpProxy': PROXY,
    'ftpProxy': PROXY,
    'sslProxy': PROXY
}
driver = webdriver.Firefox(options=options, executable_path=r'geckodriver.exe', capabilities = firefox_capabilities)
# Set the interceptor on the driver
driver.request_interceptor = interceptor 
driver.get(url)
time.sleep(50)
driver.quit()

但是网页中的IP始终相同,如果误解了代理的使用,或者我做错了什么

I am trying to make a proxy in python using selenium i have a list of free proxies from https://free-proxy-list.net/ but the ip i get is always the same, there is something wrong with this setup?

PROXY = proxy_list[11]
options = Options()
options.headless = False

webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
    "httpProxy":PROXY,
    "ftpProxy":PROXY,
    "sslProxy":PROXY,
    "noProxy":None,
    "proxyType":"MANUAL",
    "class":"org.openqa.selenium.Proxy",
    "autodetect":False
}
driver = webdriver.Firefox(options=options, executable_path=r'geckodriver.exe')
# Set the interceptor on the driver
driver.request_interceptor = interceptor 
driver.get(url)
time.sleep(5)
driver.quit()

EDIT: i am running according to the response the following code:

url = 'https://www.whatismyip.com/es/'
PROXY = proxy_list[6]
options = Options()
options.headless = False

firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['proxy'] = {
    'proxyType': "MANUAL",
    'httpProxy': PROXY,
    'ftpProxy': PROXY,
    'sslProxy': PROXY
}
driver = webdriver.Firefox(options=options, executable_path=r'geckodriver.exe', capabilities = firefox_capabilities)
# Set the interceptor on the driver
driver.request_interceptor = interceptor 
driver.get(url)
time.sleep(50)
driver.quit()

But the ip in the webpage is always the same, dunno if missunderstood the use of the proxy or i am doing something wrong

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦境 2025-02-05 01:41:53

如果您使用Firefox浏览器,

...
# set proxy
firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['proxy'] = {
    'proxyType': "MANUAL",
    'httpProxy': PROXY,
    'ftpProxy': PROXY,
    'sslProxy': PROXY
}
driver = webdriver.Firefox(options=options, executable_path=r'geckodriver.exe', capabilities = firefox_capabilities)

如果您使用Chrome,

...
chrome_options = Options()
chrome_options.add_argument('--proxy-server=' + PROXY)
chrome_options.add_argument("--headless") 
driver = webdriver.Chrome(executable_path = 'chromedriver.exe', options=chrome_options)

If you use Firefox browser,

...
# set proxy
firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['proxy'] = {
    'proxyType': "MANUAL",
    'httpProxy': PROXY,
    'ftpProxy': PROXY,
    'sslProxy': PROXY
}
driver = webdriver.Firefox(options=options, executable_path=r'geckodriver.exe', capabilities = firefox_capabilities)

If you use Chrome,

...
chrome_options = Options()
chrome_options.add_argument('--proxy-server=' + PROXY)
chrome_options.add_argument("--headless") 
driver = webdriver.Chrome(executable_path = 'chromedriver.exe', options=chrome_options)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文