|
|||||||||
chrome の変更点
#author("2021-03-18T04:38:07+00:00","default:pentacle","pentacle")
* headless chrome [#qac151ea]
*** cent7 [#qa0bf005]
''/etc/yum.repos.d/google-chrome.repo''
[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=0
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
yum -y update
yum -y install google-chrome-stable
yum -y install epel-release
yum -y install libX11 GConf2 fontconfig
yum -y install python-pip
pip install --upgrade pip
pip install selenium
yum install -y google-chrome-unstable libOSMesa google-noto-cjk-fonts
ln -s /usr/lib64/libOSMesa.so.8 /opt/google/chrome-unstable/libosmesa.so
*** ubuntu16 [#xc001eff]
apt-get install -y libappindicator1 fonts-liberation
curl -O https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome-stable_current_amd64.deb
sudo apt-get install libosmesa6
mkdir /opt/google/chrome/
ln -s /usr/lib/x86_64-linux-gnu/libOSMesa.so.8 /opt/google/chrome/libosmesa.so
''test''
google-chrome --headless --use-gl=osmesa --screenshot https://www.chromestatus.com/
* chromedriver [#n9cbda20]
wget https://chromedriver.storage.googleapis.com/2.33/chromedriver_linux64.zip
unzip chromedriver*.zip
mv chromedriver /usr/local/bin
* ffmpeg [#o86e2c9c]
sudo add-apt-repository ppa:jonathonf/ffmpeg-3
sudo apt update
sudo apt install ffmpeg libav-tools x264 x265
* JavaSample [#r3902dd9]
#pre{{
String os = System.getProperty("os.name").toLowerCase();
if (os.startsWith("windows")){
OUTPUT_DIR = "./output/";
System.setProperty("webdriver.chrome.driver", "./conf/chromedriver.exe");
}else{
OUTPUT_DIR = "./output/";
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
}
final ChromeOptions options = new ChromeOptions();
if (!os.startsWith("windows")){
options.addArguments("--headless");
options.addArguments("--use-gl=osmesa");
// options.addArguments("--disable-gpu");
FFMPEG = "ffmpeg";
}else {
FFMPEG = "C:\\\\ffmpeg\\\\bin\\\\ffmpeg.exe";
}
driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().setSize(new Dimension(width,height));
driver.get(value.getAsString());
((JavascriptExecutor) driver).executeScript(script);
new Select(driver.findElement(By.name(n))).selectByValue(v);
driver.quit();
public void capture(int i, int x, int y, int w, int h){
TakesScreenshot ts = (TakesScreenshot) new Augmenter().augment(driver);
try {
String serial = "0000"+i;
serial = serial.substring(serial.length() - 4);
File image = ts.getScreenshotAs(OutputType.FILE);
BufferedImage fullImg = ImageIO.read(image);
System.out.println(fullImg.getWidth() + ", "+ fullImg.getHeight());
if (x<0){
x = 0; y=0;
w=fullImg.getWidth() - fullImg.getWidth() %4;
h=fullImg.getHeight()- fullImg.getHeight()%4;
}
BufferedImage miniImage = fullImg.getSubimage(x, y, w, h);
ImageIO.write(miniImage, "png", image);
File sc = new File(OUTPUT_DIR + serial +".png");
FileUtils.moveFile( image, sc);
} catch (WebDriverException | IOException e) {
}
}
}}
|
|||||||||