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

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

    1. <legend id='L1pZl'><style id='L1pZl'><dir id='L1pZl'><q id='L1pZl'></q></dir></style></legend>

      <tfoot id='L1pZl'></tfoot>
        <bdo id='L1pZl'></bdo><ul id='L1pZl'></ul>

      1. 通过 Selenium - Python 在新选项卡中打开网址的最快方法是什么?

        时间:2023-06-06
        <i id='4PY4G'><tr id='4PY4G'><dt id='4PY4G'><q id='4PY4G'><span id='4PY4G'><b id='4PY4G'><form id='4PY4G'><ins id='4PY4G'></ins><ul id='4PY4G'></ul><sub id='4PY4G'></sub></form><legend id='4PY4G'></legend><bdo id='4PY4G'><pre id='4PY4G'><center id='4PY4G'></center></pre></bdo></b><th id='4PY4G'></th></span></q></dt></tr></i><div id='4PY4G'><tfoot id='4PY4G'></tfoot><dl id='4PY4G'><fieldset id='4PY4G'></fieldset></dl></div>

        <tfoot id='4PY4G'></tfoot>
            <tbody id='4PY4G'></tbody>

              <small id='4PY4G'></small><noframes id='4PY4G'>

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

                • 本文介绍了通过 Selenium - Python 在新选项卡中打开网址的最快方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想创建一个python脚本来打开很多标签

                  I want to create a python script to open up a lot tabs

                  import os
                  import selenium
                  from selenium import webdriver
                  
                  
                  driver =webdriver.Chrome('/usr/local/bin/chromedriver')
                  driver.execute_script("window.open('http://www.msn.com');")
                  driver.execute_script("window.open('http://www.cnn.com');")
                  driver.execute_script("window.open('http://www.yahoo.com');")
                  driver.execute_script("window.open('https://www.apple.com');")
                  driver.execute_script("window.open('https://www.google.com');")
                  driver.execute_script("window.open('https://www.stackoverflow.com');")
                  
                  # driver.quit()
                  

                  当我跑步时,我得到了

                  我现在拥有的是最快的方法吗?

                  Is what I have right now is the fastest way?

                  我曾经有过这个

                  # -*- coding: utf-8 -*-
                  
                  import os
                  import selenium
                  from selenium import webdriver
                  from selenium.webdriver.common.keys import Keys
                  
                  driver =webdriver.Chrome('/usr/local/bin/chromedriver')
                  
                  #1
                  driver.get("http://msn.com")
                  
                  #2
                  driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't')
                  driver.switch_to.window(driver.window_handles[-1])
                  driver.get("http://cnn.com")
                  
                  #3
                  driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't')
                  driver.switch_to.window(driver.window_handles[-1])
                  driver.get("http://www.yahoo.com")
                  
                  #4
                  driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't')
                  driver.switch_to.window(driver.window_handles[-1])
                  driver.get("https://www.apple.com")
                  
                  #5
                  driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't')
                  driver.switch_to.window(driver.window_handles[-1])
                  driver.get("https://www.google.com")
                  
                  #6
                  driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't')
                  driver.switch_to.window(driver.window_handles[-1])
                  driver.get("https://www.stackoverflow.com")
                  

                  它可以工作,但它很痛苦.

                  It works but it is painfully slow.

                  我现在从 6 个开始,但我想加载 100 个标签.

                  I start with 6 now, but I want to load 100 tabs.

                  另外,我如何摆脱我的第一个奇怪的标签?我什至确定它为什么在那里.

                  Also, how do I get rid of my first weird looking tab? I am even sure why it is there.

                  推荐答案

                  升级你MAC上的chromedriver(>2.25)/chrome浏览器(>55.0),去掉空数据;标签.您可以使用 threadingmultiprocessing 来加快处理速度.

                  Upgrade the chromedriver(>2.25)/chrome browser(>55.0) on your MAC to remove the empty data; tab. You can use threading or multiprocessing to speed up the process.

                  from multiprocessing import Process
                  import os
                  import selenium
                  from selenium import webdriver
                  from selenium.webdriver.common.keys import Keys
                  
                  driver =webdriver.Chrome('/usr/local/bin/chromedriver')
                  driver.get("http://msn.com")
                  def func1():
                    print 'launching: MSN'
                   driver.execute_script("window.open('http://www.msn.com');")
                  
                  def func2():
                    print 'launching: CNN'
                    driver.execute_script("window.open('http://www.cnn.com');")
                  
                  if __name__ == '__main__':
                    p1 = Process(target=func1)
                    p1.start()
                    p2 = Process(target=func2)
                    p2.start()
                    p1.join()
                    p2.join()
                  
                  def runInParallel(*fns):
                    proc = []
                    for fn in fns:
                      p = Process(target=fn)
                      p.start()
                      proc.append(p)
                    for p in proc:
                      p.join()
                  
                  runInParallel(func1, func2)
                  

                  取决于你有多少 CPU、机器的负载、计算机中发生的许多事情的时间都会影响线程/进程的启动时间.此外,由于进程在创建后立即启动,因此创建进程的开销也必须以您看到的时间差来计算.

                  Depending on how many CPUs you have, the load of the machine, the timing of many things happening in the computer will have an influence on the time the threads/process start. Also, since the processes are started right after creation, the overhead of creating a process also has to be calculated in the time difference you see.

                  这篇关于通过 Selenium - Python 在新选项卡中打开网址的最快方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:InvalidArgumentException:消息:无效参数:用户数据目录已在使用错误使用 --user-data- 下一篇:在 nseindia.com 上单击获取数据按钮以获取每月结算统计信息不会使用 Selenium 和 Python 获取

                  相关文章

                    <bdo id='fKE3l'></bdo><ul id='fKE3l'></ul>
                  <legend id='fKE3l'><style id='fKE3l'><dir id='fKE3l'><q id='fKE3l'></q></dir></style></legend>
                  1. <small id='fKE3l'></small><noframes id='fKE3l'>

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