Outils pour capturer et convertir le Web

Convertir les URL et HTML en DOCX

API Perl

Ajout de la possibilité de convertir du HTML ou des pages Web into Les documents Word de votre application n’ont jamais été aussi simples avec API Perl de GrabzIt. Cependant, avant de commencer, rappelez-vous qu'après avoir appelé le URLToDOCX, HTMLToDOCX or FileToDOCX méthodes le Save or SaveTo La méthode doit être appelée pour créer le fichier DOCX.

Options de base

La capture de pages Web au format DOCX convertit la page Web entière into un document Word pouvant comporter plusieurs pages. Un seul paramètre est requis pour convertir une page Web into un document Word ou à convertir HTML en DOCX comme indiqué dans les exemples ci-dessous.

$grabzIt->URLToDOCX("https://www.tesla.com");
# Then call the Save or SaveTo method
$grabzIt->HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>");
# Then call the Save or SaveTo method
$grabzIt->FileToDOCX("example.html");
# Then call the Save or SaveTo method

Identifiant personnalisé

Vous pouvez transmettre un identifiant personnalisé au DOCX Comme indiqué ci-dessous, cette valeur est ensuite renvoyée à votre gestionnaire GrabzIt Perl. Par exemple, cet identifiant personnalisé pourrait être un identifiant de base de données, permettant d'associer un document DOCX à un enregistrement de base de données particulier.

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItDOCXOptions->new();
$options->customId(123456);

$grabzIt->URLToDOCX("https://www.tesla.com", $options);
# Then call the Save method
$grabzIt->Save("http://www.example.com/handler.pl");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItDOCXOptions->new();
$options->customId(123456);

$grabzIt->HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>", $options);
# Then call the Save method
$grabzIt->Save("http://www.example.com/handler.pl");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItDOCXOptions->new();
$options->customId(123456);

$grabzIt->FileToDOCX("example.html", $options);
# Then call the Save method
$grabzIt->Save("http://www.example.com/handler.pl");

En-têtes et pieds de page

Pour ajouter un en-tête ou un pied de page à un document Word, vous pouvez demander à appliquer un programme particulier. modèle au DOCX en cours de génération. Ce modèle doit être saved à l'avance et spécifiera le contenu de l'en-tête et du pied de page avec toutes les variables spéciales. Dans l'exemple de code ci-dessous, l'utilisateur utilise un modèle qu'ils ont créé, appelé "mon modèle".

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItDOCXOptions->new();
$options->templateId("my template");

$grabzIt->URLToDOCX("https://www.tesla.com", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.docx");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItDOCXOptions->new();
$options->templateId("my template");

$grabzIt->HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.docx");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItDOCXOptions->new();
$options->templateId("my template");

$grabzIt->FileToDOCX("example.html", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.docx");

Convertir un élément HTML en DOCX

Si vous voulez simplement convertir un élément HTML tel qu'un div ou un span directement into Un document Word que vous pouvez utiliser avec la bibliothèque Perl de GrabzIt. Vous devez passer le Sélecteur CSS de l'élément HTML que vous souhaitez convertir en targetElement méthode de GrabzItDOCXOptions classe.

...
<span id="Article">
<p>This is the content I am interested in.</p>
<img src="myimage.jpg">
</span>
...

Dans cet exemple, nous souhaitons capturer tout le contenu de la plage portant l’id de ArticlePar conséquent, nous transmettons cela à l'API GrabzIt comme indiqué ci-dessous.

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItDOCXOptions->new();
$options->targetElement("#Article");

$grabzIt->URLToDOCX("http://www.bbc.co.uk/news", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.docx");