V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
bruce00
V2EX  ›  问与答

求助, Python 爬虫中 chrome 启用 headless 设置后运行速度变得很慢

  •  
  •   bruce00 · Dec 4, 2018 · 3076 views
    This topic created in 2704 days ago, the information mentioned may be changed or developed.

    同样的环境和 options 代码设置,家里电脑就能很快运行

    在性能差不多的单位的电脑上,没启用 headless 时 chrome 秒开,启用之后就半天没反应。。。

    会是什么原因呢?有遇到过类似情况的大佬吗

    代码如下:

    from selenium.webdriver.chrome.options import Options
    
    def getpage(url):
        
        chrome_options = Options()
        chrome_options.add_argument('--headless')
        driver = webdriver.Chrome(options=chrome_options)
        driver.get(url)
    
    3 replies    2018-12-04 12:46:30 +08:00
    binux
        1
    binux  
       Dec 4, 2018 via Android   ❤️ 1
    我猜一个,页面上有慢资源一直在加载,有 UI 的时候你看到以为加载完了,但是实际上还在等待 Page load
    justseemore
        2
    justseemore  
       Dec 4, 2018   ❤️ 1
    把图片渲染关了,应该会快点,但还是比 requests 慢!
    bruce00
        3
    bruce00  
    OP
       Dec 4, 2018
    @binux 应该不是,没启用 headless 的时候很快就抓取到页面资源并退出 chrome,开始下一步了,感觉是这块代码或者浏览器的原因
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4643 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 09:41 · PVG 17:41 · LAX 02:41 · JFK 05:41
    ♥ Do have faith in what you're doing.