<legend id='2rxjE'><style id='2rxjE'><dir id='2rxjE'><q id='2rxjE'></q></dir></style></legend>
    <bdo id='2rxjE'></bdo><ul id='2rxjE'></ul>
  • <i id='2rxjE'><tr id='2rxjE'><dt id='2rxjE'><q id='2rxjE'><span id='2rxjE'><b id='2rxjE'><form id='2rxjE'><ins id='2rxjE'></ins><ul id='2rxjE'></ul><sub id='2rxjE'></sub></form><legend id='2rxjE'></legend><bdo id='2rxjE'><pre id='2rxjE'><center id='2rxjE'></center></pre></bdo></b><th id='2rxjE'></th></span></q></dt></tr></i><div id='2rxjE'><tfoot id='2rxjE'></tfoot><dl id='2rxjE'><fieldset id='2rxjE'></fieldset></dl></div>

      1. <small id='2rxjE'></small><noframes id='2rxjE'>

        <tfoot id='2rxjE'></tfoot>

      2. 如何旋转 Selenium 网络浏览器 IP 地址

        时间:2023-07-04
        <legend id='HFpy2'><style id='HFpy2'><dir id='HFpy2'><q id='HFpy2'></q></dir></style></legend>
          <bdo id='HFpy2'></bdo><ul id='HFpy2'></ul>

          1. <tfoot id='HFpy2'></tfoot>

            <i id='HFpy2'><tr id='HFpy2'><dt id='HFpy2'><q id='HFpy2'><span id='HFpy2'><b id='HFpy2'><form id='HFpy2'><ins id='HFpy2'></ins><ul id='HFpy2'></ul><sub id='HFpy2'></sub></form><legend id='HFpy2'></legend><bdo id='HFpy2'><pre id='HFpy2'><center id='HFpy2'></center></pre></bdo></b><th id='HFpy2'></th></span></q></dt></tr></i><div id='HFpy2'><tfoot id='HFpy2'></tfoot><dl id='HFpy2'><fieldset id='HFpy2'></fieldset></dl></div>

                <small id='HFpy2'></small><noframes id='HFpy2'>

                  <tbody id='HFpy2'></tbody>
                1. 本文介绍了如何旋转 Selenium 网络浏览器 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 Python 脚本,它每 30 秒访问一次网站,每次我都需要不同的 IP 地址.

                  I have a Python script that visits a website every 30 sec, and I would need to have a different IP address each time.

                  什么是最好/最省时的解决方案?

                  What would be the best/most time effective solution?

                  • 在线抓取免费代理?你知道从多个来源收集代理的 python 脚本吗?

                  • scraping free proxies online? Do you know a python script that gather proxies from many sources?

                  每次使用 Tor 浏览器都有不同的 IP(我在 aws ec2 实例上使用 selenium,你们知道如何在 Ubuntu 服务器上使用 Tor 浏览器的教程吗?)

                  use Tor browser to have a different IP each time (I'm using selenium on an aws ec2 instance, you guys know a tutorial on how to use Tor browser on Ubuntu server?)

                  其他方法?

                  推荐答案

                  要收集和使用不同的代理,一个强大的解决方案是使用在 免费代理列表 使用以下解决方案:

                  To gather and use different proxies a robust solution would be to make proxied requests to the website using the newly active proxies which gets listed within the Free Proxy List using the following solution:

                  • 代码块:

                  • Code Block:

                  from selenium import webdriver
                  from selenium.webdriver.support.ui import WebDriverWait
                  from selenium.webdriver.common.by import By
                  from selenium.webdriver.support import expected_conditions as EC
                  from selenium.common.exceptions import TimeoutException
                  
                  options = webdriver.ChromeOptions()
                  options.add_argument("start-maximized")
                  options.add_experimental_option("excludeSwitches", ["enable-automation"])
                  options.add_experimental_option('useAutomationExtension', False)
                  driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:WebDriverschromedriver.exe')
                  driver.get("https://sslproxies.org/")
                  driver.execute_script("return arguments[0].scrollIntoView(true);", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//table[@class='table table-striped table-bordered dataTable']//th[contains(., 'IP Address')]"))))
                  ips = [my_elem.get_attribute("innerHTML") for my_elem in WebDriverWait(driver, 5).until(EC.visibility_of_all_elements_located((By.XPATH, "//table[@class='table table-striped table-bordered dataTable']//tbody//tr[@role='row']/td[position() = 1]")))]
                  ports = [my_elem.get_attribute("innerHTML") for my_elem in WebDriverWait(driver, 5).until(EC.visibility_of_all_elements_located((By.XPATH, "//table[@class='table table-striped table-bordered dataTable']//tbody//tr[@role='row']/td[position() = 2]")))]
                  driver.quit()
                  proxies = []
                  for i in range(0, len(ips)):
                      proxies.append(ips[i]+':'+ports[i])
                  print(proxies)
                  for i in range(0, len(proxies)):
                      try:
                          print("Proxy selected: {}".format(proxies[i]))
                          options = webdriver.ChromeOptions()
                          options.add_argument('--proxy-server={}'.format(proxies[i]))
                          driver = webdriver.Chrome(options=options, executable_path=r'C:WebDriverschromedriver.exe')
                          driver.get("https://www.whatismyip.com/proxy-check/?iref=home")
                          if "Proxy Type" in WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "p.card-text"))):
                              break
                      except Exception:
                          driver.quit()
                  print("Proxy Invoked")
                  

                2. 控制台输出:

                3. Console Output:

                  ['190.7.158.58:39871', '175.139.179.65:54980', '186.225.45.146:45672', '185.41.99.100:41258', '43.230.157.153:52986', '182.23.32.66:30898', '36.37.160.253:31450', '93.170.15.214:56305', '36.67.223.67:43628', '78.26.172.44:52490', '36.83.135.183:3128', '34.74.180.144:3128', '206.189.122.177:3128', '103.194.192.42:55546', '70.102.86.204:8080', '117.254.216.97:23500', '171.100.221.137:8080', '125.166.176.153:8080', '185.146.112.24:8080', '35.237.104.97:3128']
                  
                  Proxy selected: 190.7.158.58:39871
                  
                  Proxy selected: 175.139.179.65:54980
                  
                  Proxy selected: 186.225.45.146:45672
                  
                  Proxy selected: 185.41.99.100:41258
                  

                4. 这篇关于如何旋转 Selenium 网络浏览器 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 python webdriver 中为 chrome 设置代理? 下一篇:如何为 python selenium 3.8.0 设置'driver.get'的超时?

                  相关文章

                5. <i id='EYwcB'><tr id='EYwcB'><dt id='EYwcB'><q id='EYwcB'><span id='EYwcB'><b id='EYwcB'><form id='EYwcB'><ins id='EYwcB'></ins><ul id='EYwcB'></ul><sub id='EYwcB'></sub></form><legend id='EYwcB'></legend><bdo id='EYwcB'><pre id='EYwcB'><center id='EYwcB'></center></pre></bdo></b><th id='EYwcB'></th></span></q></dt></tr></i><div id='EYwcB'><tfoot id='EYwcB'></tfoot><dl id='EYwcB'><fieldset id='EYwcB'></fieldset></dl></div>

                  <small id='EYwcB'></small><noframes id='EYwcB'>

                  1. <tfoot id='EYwcB'></tfoot>

                    • <bdo id='EYwcB'></bdo><ul id='EYwcB'></ul>
                    1. <legend id='EYwcB'><style id='EYwcB'><dir id='EYwcB'><q id='EYwcB'></q></dir></style></legend>