firefox和chrome的简单对比

为了爬虫,用了selenium操作两种浏览器

1.chrome,内核78.0.3904.70

2.firefox,内核68.3.0

两种都支持无头模式,便于爬取。

共同的配置如下:

        chrome_options=webdriver.ChromeOptions()
        chrome_options.add_argument('-headless')
        chrome_options.add_argument('-disable-gpu')
        #chrome_options.set_page_load_timeout(5)
        #prw=webdriver.Firefox(options=chrome_options)
        capa = DesiredCapabilities.CHROME
        capa["pageLoadStrategy"] = "none"
        save_dir=os.path.join(save_root_dir,'2')

跑这段配置:

    print('pre',time.ctime())
    prw=webdriver.Chrome(desired_capabilities=capa,options=chrome_options)
    prw.set_page_load_timeout(5)
    print('configed---',time.ctime())

两个时间点之差,firefox:6S,chrome:2S

做一个抓取:

prw.get(url)
time.sleep(2)
 resp=prw.page_source
    prw.quit()
    if resp is not None:
        bs=BeautifulSoup(resp,'lxml')
        pics=bs.select('img.image_original_original')
        for pic in pics:
            #print(pic)
            download_pic(pic.get('src'))

共同有个2S延时,firefox:9s,chrome:4s

chrome还可以往下调延时,firefox往下调延时就不能取出resp了。

google确实厉害。

有selenium之类的坑欢迎留言交流。

发布了12 篇原创文章 · 获赞 0 · 访问量 151

猜你喜欢

转载自blog.csdn.net/weixin_37281967/article/details/103839867