<tfoot id='4blxN'></tfoot>

      <bdo id='4blxN'></bdo><ul id='4blxN'></ul>
    <legend id='4blxN'><style id='4blxN'><dir id='4blxN'><q id='4blxN'></q></dir></style></legend>

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

  1. <small id='4blxN'></small><noframes id='4blxN'>

    1. Selenium Threads:如何使用代理运行多线程浏览器(python)

      Selenium Threads: how to run multi-threaded browser with proxy ( python)(Selenium Threads:如何使用代理运行多线程浏览器(python))
      • <bdo id='1lAnq'></bdo><ul id='1lAnq'></ul>

              <tbody id='1lAnq'></tbody>
            • <tfoot id='1lAnq'></tfoot>

              <small id='1lAnq'></small><noframes id='1lAnq'>

              • <i id='1lAnq'><tr id='1lAnq'><dt id='1lAnq'><q id='1lAnq'><span id='1lAnq'><b id='1lAnq'><form id='1lAnq'><ins id='1lAnq'></ins><ul id='1lAnq'></ul><sub id='1lAnq'></sub></form><legend id='1lAnq'></legend><bdo id='1lAnq'><pre id='1lAnq'><center id='1lAnq'></center></pre></bdo></b><th id='1lAnq'></th></span></q></dt></tr></i><div id='1lAnq'><tfoot id='1lAnq'></tfoot><dl id='1lAnq'><fieldset id='1lAnq'></fieldset></dl></div>
                <legend id='1lAnq'><style id='1lAnq'><dir id='1lAnq'><q id='1lAnq'></q></dir></style></legend>
                本文介绍了Selenium Threads:如何使用代理运行多线程浏览器(python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在编写一个脚本来使用具有多个线程的代理访问网站,但现在我被困在多个线程中,当我运行下面的脚本时,它会打开 5 个浏览器,但所有 5 个都使用 1 个代理,我想要 5 个浏览器使用不同的代理,有人可以帮我完成吗?谢谢你

                I'm writing a script to access a website using proxies with multiple threads but now I'm stuck in multiple threads, when I run the script below, it opens 5 browsers but all 5 use 1 proxy, I want 5 browsers to use different proxies, can someone help me complete it? thank you

                这是我的脚本:

                from selenium import webdriver
                from selenium import webdriver
                import time , random
                import threading
                
                
                def e():
                
                    a = open("sock2.txt", "r")
                    for line in a.readlines():
                
                        b = line
                        prox = b.split(":")
                        IP = prox[0]
                        PORT = int(prox[1].strip("
                "))
                        print(IP)
                        print(PORT)
                
                
                        profile = webdriver.FirefoxProfile()
                        profile.set_preference("network.proxy.type", 1)
                        profile.set_preference("network.proxy.socks", IP)
                        profile.set_preference("network.proxy.socks_port", PORT)
                        try:
                
                            driver = webdriver.Firefox(firefox_profile=profile)
                            driver.get("http://www.whatsmyip.org/")
                        except:
                            print("Proxy Connection Error")
                            driver.quit()
                        else:
                            time.sleep(random.randint(40, 70))
                            driver.quit()
                for i in range(5):
                    t = threading.Thread(target=e)
                    t.start()
                

                (祝大家新年快乐,万事如意)

                (Wish everyone has a happy and lucky new year)

                推荐答案

                Dominik Lao 正确捕获了它 - 每个线程从头开始处理文件.这可能是它的样子:

                Dominik Lao captured it correctly - each threads processes the file from the beginning. Here's probably how it should look like:

                from selenium import webdriver
                from selenium import webdriver
                import time , random
                import threading
                
                
                def e(ip, port):
                    profile = webdriver.FirefoxProfile()
                    profile.set_preference("network.proxy.type", 1)
                    profile.set_preference("network.proxy.socks", IP)
                    profile.set_preference("network.proxy.socks_port", PORT)
                    try:
                        driver = webdriver.Firefox(firefox_profile=profile)
                        driver.get("http://www.whatsmyip.org/")
                    except:
                        print("Proxy Connection Error")
                        driver.quit()
                    else:
                        time.sleep(random.randint(40, 70))
                        driver.quit()
                
                my_threads = []
                with open("sock2.txt", "r") as fd:
                    for line in fd.readlines():
                        line = line.strip()
                        if not line:
                           continue
                        prox = line.split(":")
                        ip = prox[0]
                        port = int(prox[1])
                        print('-> {}:{}'.format(ip, port))
                        t = threading.Thread(target=e, args=(ip, port,))
                        t.start()
                        my_threads.append(t)
                
                for t in my_threads:
                    t.join()
                

                这篇关于Selenium Threads:如何使用代理运行多线程浏览器(python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                env: python: No such file or directory(env: python: 没有这样的文件或目录)
                How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)
                  <bdo id='MFMFy'></bdo><ul id='MFMFy'></ul>
                  • <small id='MFMFy'></small><noframes id='MFMFy'>

                      <tbody id='MFMFy'></tbody>

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

                          <tfoot id='MFMFy'></tfoot>