Disclaimer: Respect bloggers original articles, please indicate the source. If wrong, correct me hope. Contact: [email protected] https://blog.csdn.net/Supreme_Sir/article/details/89710069
Different from the previous article as mentioned by the client browser will HTML
turn canvas
the way again generated images, the contents of this record is a server-side ( Windows Server
) screenshot tool. The tool is characterized by: By java
no browser interface calling code .exe
file, so no browser interface in the background HTML
rendering and screenshots, screenshots and save to the specified path. code show as below:
ScreenshotDemo.java
import java.io.File;
import java.io.IOException;
public class ScreenshotDemo{
// 工具所在根目录
private static String root = "E:\\cut\\截图工具";
private static String jsPath = root + File.separator + "screenshot.js ";
private static String exePath = root + File.separator + "phantomjs.exe";
// 调用phantomjs程序,并传入js文件,并通过流拿回需要的数据。
public static void getParseredHtml2(String url,String path) throws IOException{
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(exePath + " " + jsPath + " " + url+" "+path);
}
// 执行测试
public static void main(String[] args) throws IOException {
getParseredHtml2("http://www.baidu.com","E:/Baidu.png");
}
}
FIG file path as follows:
PS:
- If I have written to intercept
HTML
file, make sure the file is noECMAScript 6(简称ES6)
grammar, because the screenshot tool does not! support! hold! ! ! - Sample code and tools CSDN download link: https://download.csdn.net/download/supreme_sir/11149969
- No Download Credits may leave the mailbox or send mail into the mailbox at the top of this article copyright notice in the comments area, Bo Lord replies in the first time after seeing.
![I declare: Now from work!](https://img-blog.csdnimg.cn/20190430150941176.jpg)