【发布时间】:2019-03-24 10:33:30
【问题描述】:
我正在尝试在 docker 容器 ubuntu 18.04 中以无头模式使用 geckodriver 运行 selenium。这是我的代码:
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(2)
newHeight = driver.execute_script("return document.body.scrollHeight")
print('scrolling..')
if newHeight == lastHeight:
print(f'scrolling done..')
list_of_images = driver.find_elements_by_css_selector('._2eea a')
print(f'collecting: {fp_url}')
images = []
for image in list_of_images:
url = image.get_attribute('href')
if 'type=3' in str(url):
print(f'append: {url}')
images.append(url)
# clear_memory()
print(f'total: {len(images)} memes')
count = 1
else:
lastHeight = newHeight
我在本地计算机上尝试时没有出错,但是当我在 docker 容器中尝试时,页面似乎不会滚动。这是我的驱动程序设置:
options = webdriver.FirefoxOptions()
options.add_argument('--hide-scrollbars')
options.add_argument('--disable-gpu')
options.add_argument('-headless')
driver = webdriver.Firefox(firefox_options=options, executable_path=os.path.join(os.getcwd(), "geckodriver"))
【问题讨论】:
标签: python selenium docker firefox geckodriver