調べてもなかなか出てこなかったのでメモ。
(もっといい方法があればどなたか教えてください)
- URLリストを外部ファイル(list.tsv)から読み込んで
- それらに対してスクリーンショットを撮る
- フルページで撮る
- pythonの変数に行を突っ込んで回してます
screen_shot.robot
*** Settings ***
Library SeleniumLibrary
Variables ./import.py
*** Keywords ***
Create Chrome Driver
${options} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys
Call method ${options} add_argument --headless
Create webdriver Chrome chrome_options=${options}
*** Test Cases ***
キーワード
Create Chrome Driver
${w} = Execute JavaScript return document.body.scrollWidth
${h} = Execute JavaScript return document.body.scrollHeight
Set Window Size ${w} ${h}
Set ScreenShot Directory path=screenshot
${length}= Get Length ${conditions}
:FOR ${idx} IN RANGE ${length}
\ Go To @{urls}[${idx}]
\ Capture Page Screenshot filename=@{conditions}[${idx}].png
import.py
import csv
with open('list.tsv') as f:
reader = csv.reader(f, delimiter='\t')
l = [row for row in reader]
l_T = [list(x) for x in zip(*l)]
conditions = l_T[0]
urls = l_T[1]
list.tsv
ねこ https://www.google.com/search?q=%E3%81%AD%E3%81%93&tbm=isch
いぬ https://www.google.com/search?q=%E3%81%84%E3%81%AC&tbm=isch
さる https://www.google.com/search?q=%E3%81%95%E3%82%8B&tbm=isch