phantomjs

基于phantomjs的截图优化JS信息

星期三, 四月 5th, 2023 | computer, JAVA-and-J2EE, linux | 没有评论

phantomjs是比较老的一种模拟抓取及截图,这个是以前处理截图的一种优化js信息做个留档

以后应该是不用了

img.js和rasterize.js两个文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var page = require('webpage').create(), system = require('system'), address, output, size;
 
if (system.args.length < 3 || system.args.length > 5) {
    phantom.exit(1);
} else {
    address = system.args[1];
    output = system.args[2];
    //定义宽高
   /* page.viewportSize = {
        width : 1024,
        height : 768
    };*/
    page.open(address, function(status) {
        var bb = page.evaluate(function() {
            return document.getElementsByTagName('html')[0].getBoundingClientRect();
        });
        page.clipRect = {
            top : bb.top,
            left : bb.left,
            width : bb.width,
            height : bb.height
        };
        window.setTimeout(function() {
            page.render(output);
            page.close();
            console.log('渲染成功...');
            console.log(address);
            phantom.exit();
        }, 1000);
    });
}

› Continue reading

Tags:

Search

文章分类

Links

Meta