在Docker镜像上开发抓取脚本 – 如何克服视觉浏览器的不足?

我想从网上抓取信息,以前的一个尝试教会了我,docker工作将会对我的脚本运行起到很大的作用,因为我在mac os x上开发脚本,然后在vm上运行它,通常它不会运行因为Ubuntu的依赖关系并不存在,而且已经certificate很难构build。

Docker克服了依赖性问题,但是现在我又面临一个不同的问题,那就是我需要在Docker镜像上以非无头模式开发脚本,看看它在做什么(或者至less我认为我是这样做的),而是在docker上不要认为可以在非无头模式下运行浏览器。

别人如何克服这个问题或以其他方式绕过它?

我在@Harald Norgren帮助我在这个图像上使用python3,selenium

这是我正在运行的脚本,但它还没有做任何事情,我只是包括它提供更多的背景,这是有帮助的。

import csv import time from selenium import webdriver import os import logging #logging.warning(data_store+file) import json project_dir = os.path.dirname(os.path.realpath(__file__)) data_store = project_dir+"/trends-data/" archive_folder = "archive" data_archive = data_store + archive_folder + "/" chromeOptions = webdriver.ChromeOptions() chromeOptions.add_argument("--headless") prefs = {"download.default_directory" : data_store} chromeOptions.add_experimental_option("prefs",prefs) driver = webdriver.Chrome( project_dir+'/chromedriver', chrome_options=chromeOptions ) driver.get('https://trends.google.co.uk/trends/explore?q=query'); time.sleep(5) driver.find_element_by_class_name("ic_googleplus_reshare").click() time.sleep(5) driver.find_element_by_class_name("csv-image").click() time.sleep(5) driver.quit()