将图像的宽度和高度设置为-1,以使图像与目标HTML元素的大小匹配。 通过将浏览器高度设置为-1,浏览器窗口的长度也会自动增加,以确保目标HTML元素是否适合 into浏览器。
下面的示例代码显示了使用ASP.NET从网页捕获HTML元素作为图像是多么容易。 刚开始创建图像 下载ASP.NET库, 拿你的 关键和秘密 然后 使用演示 包含在其中。 然后检查 ASP.NET的API文档 找出使用GrabzIt API的所有方法。
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
ImageOptions options = new ImageOptions();
options.OutputWidth = -1;
options.OutputHeight = -1;
options.BrowserHeight = -1;
options.Format = ImageFormat.jpg;
options.TargetElement = "#Article";
grabzIt.URLToImage("http://www.example.com/", options);
grabzIt.SaveTo("images/result.jpg");
下面的示例代码显示了使用Java从网页捕获HTML元素作为图像是多么容易。 刚开始创建图像 下载Java库, 拿你的 关键和秘密 然后 使用演示 包含在其中。 然后检查 Java API文档 找出使用GrabzIt API的所有方法。
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
ImageOptions options = new ImageOptions();
options.setWidth(-1);
options.setHeight(-1);
options.setBrowserHeight(-1);
options.setFormat(ImageFormat.JPG);
options.setTargetElement("#Article");
grabzIt.URLToImage("http://www.example.com/", options);
grabzIt.SaveTo("images/result.jpg");
下面的示例代码显示了使用Node.js从网页捕获HTML元素作为图像是多么容易。 刚开始创建图像 下载Node.js程序包, 拿你的 关键和秘密 然后 使用演示 包含在其中。 然后检查 Node.js的API文档 找出使用GrabzIt API的所有方法。
var grabzit = require('grabzit');
var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");
// The minus ones indicates that image should not be cropped
var options = {"browserHeight":-1, "width":-1, "height":-1, "format":"jpg", "target":"#Article"};
client.url_to_image("http://www.example.com/", options);
client.save_to("images/result.jpg", function (error, id){
if (error != null){
throw error;
}
});
下面的示例代码显示了使用Perl从网页捕获HTML元素作为图像是多么容易。 刚开始创建图像 下载Perl库, 拿你的 关键和秘密 然后 使用演示 包含在其中。 然后检查 Perl的API文档 找出使用GrabzIt API的所有方法。
#!/usr/bin/perl
use GrabzItClient;
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");
$options = GrabzItImageOptions->new();
$options->browserHeight(-1);
$options->width(-1);
$options->height(-1);
$options->targetElement("#Article");
$grabzIt->URLToImage("http://www.example.com/", $options);
$grabzIt->SaveTo("images/result.jpg");
下面的示例代码显示了使用PHP从网页捕获HTML元素作为图像是多么容易。 刚开始创建图像文件 下载PHP库, 拿你的 关键和秘密 然后 使用演示 包含在其中。 然后检查 PHP的API文档 找出使用GrabzIt API的所有方法。
include("GrabzItClient.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
// The -1 indicates that image should not be cropped
$options = new \GrabzIt\GrabzItImageOptions();
$options->setWidth(-1);
$options->setHeight(-1);
$options->setBrowserHeight(-1);
$options->setFormat("jpg");
$options->setTargetElement("#Article");
$grabzIt->URLToImage("http://www.example.com/", $options);
$grabzIt->SaveTo("images/result.jpg");
下面的示例代码显示了使用Python从网页捕获HTML元素作为图像是多么容易。 刚开始创建图像 下载Python库, 拿你的 关键和秘密 然后 使用演示 包含在其中。 然后检查 Python的API文档 找出使用GrabzIt API的所有方法。
from GrabzIt import GrabzItClient
grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")
# The -1 indicates that image should not be cropped
options = GrabzItImageOptions.GrabzItImageOptions()
options.width = 250
options.height = 250
options.browserHeight = -1
options.format = "jpg"
options.targetElement = "#Article"
grabzIt.URLToImage("http://www.example.com/", options)
grabzIt.SaveTo("images/result.jpg")
下面的示例代码显示了使用我们的REST API从网页捕获HTML元素作为图像的便捷性。 然后检查 REST API的API文档 找出可以自定义捕获内容的所有方法。
https://api.grabz.it/services/convert.ashx?key=Sign in to view your Application Key&width=-1&height=-1&bheight=-1&target=%23Article&format=jpg&url=https%3A%2F%2Fwww.example.com%2F