gpt4 book ai didi

coffeescript - 如何使用phantomjs从站点下载图像

转载 作者:行者123 更新时间:2023-12-04 09:00:29 24 4
gpt4 key购买 nike

我想从网站上保存一些图像。目前我可以获得图像的路径,但我不知道如何使用 phantomJs 获取和保存图像。

findRotationTeaserImages = ->
paths = page.evaluate ->
jQuery('.rotate img').map(-> return this.src).get()

for path, i in paths
console.log(path);
//save the image

最佳答案

我知道这是一个老问题,但是您可以通过将每个图像的尺寸和位置存储在一个对象上,然后更改 phantomjs page.clipRect 以便 page.render() 方法仅呈现其中的区域来实现这一点图像是。这是一个示例,从 http://dribbble.com/ 中抓取多个图像:

var page = require('webpage').create();

page.open('http://dribbble.com/', function() {

page.includeJs('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',function() {

var images = page.evaluate(function() {
var images = [];
function getImgDimensions($i) {
return {
top : $i.offset().top,
left : $i.offset().left,
width : $i.width(),
height : $i.height()
}
}
$('.dribbble-img img').each(function() {
var img = getImgDimensions($(this));
images.push(img);
});

return images;
});

images.forEach(function(imageObj, index, array){
page.clipRect = imageObj;
page.render('images/'+index+'.png')
});

phantom.exit();
});
});

关于coffeescript - 如何使用phantomjs从站点下载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16716753/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com