Herramientas para capturar y convertir la web

Convierta URL y HTML a DOCX

API de Python

Agregar la capacidad de convertir HTML o páginas web into Los documentos de Word para su aplicación nunca han sido tan fáciles con API de Python de GrabzIt. Sin embargo, antes de comenzar, recuerde que después de llamar al URLToDOCX, HTMLToDOCX or FileToDOCX métodos de Save or SaveTo Se debe llamar al método para crear realmente el DOCX.

Opciones basicas

La captura de páginas web a medida que DOCX convierte la página web completa into un documento de Word que puede constar de muchas páginas. Solo se requiere un parámetro para convertir una página web into un documento de Word o para convertir HTML a DOCX como se muestra en los ejemplos a continuación.

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

Identificador personalizado

Puede pasar un identificador personalizado a DOCX métodos como se muestra a continuación, este valor se devuelve a su controlador GrabzIt Python. Por ejemplo, este identificador personalizado podría ser un identificador de base de datos, permitiendo que un documento DOCX se asocie con un registro de base de datos particular.

from GrabzIt import GrabzItDOCXOptions
from GrabzIt import GrabzItClient

grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzItDOCXOptions.GrabzItDOCXOptions()
options.customId = "123456"

grabzIt.URLToDOCX("https://www.tesla.com", options)
# Then call the Save method
grabzIt.Save("http://www.example.com/handler.py")
from GrabzIt import GrabzItDOCXOptions
from GrabzIt import GrabzItClient

grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzItDOCXOptions.GrabzItDOCXOptions()
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.py")
from GrabzIt import GrabzItDOCXOptions
from GrabzIt import GrabzItClient

grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzItDOCXOptions.GrabzItDOCXOptions()
options.customId = "123456"

grabzIt.FileToDOCX("example.html", options)
# Then call the Save method
grabzIt.Save("http://www.example.com/handler.py")

Encabezados y pies de página

Para agregar un encabezado o pie de página a un documento de Word, puede solicitar que desee aplicar un determinado plantilla al DOCX que se genera. Esta plantilla debe ser saved de antemano y especificará el contenido del encabezado y pie de página junto con cualquier variable especial. En el código de ejemplo a continuación, el usuario está usando una plantilla que creó llamada "mi plantilla".

from GrabzIt import GrabzItDOCXOptions
from GrabzIt import GrabzItClient

grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzItDOCXOptions.GrabzItDOCXOptions()
options.templateId = "my template"

grabzIt.URLToDOCX("https://www.tesla.com", options)
# Then call the Save or SaveTo method
grabzIt.SaveTo("result.docx")
from GrabzIt import GrabzItDOCXOptions
from GrabzIt import GrabzItClient

grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzItDOCXOptions.GrabzItDOCXOptions()
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")
from GrabzIt import GrabzItDOCXOptions
from GrabzIt import GrabzItClient

grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzItDOCXOptions.GrabzItDOCXOptions()
options.templateId = "my template"

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

Convertir elemento HTML a DOCX

Si solo desea convertir un elemento HTML como un div o span directamente into un documento de Word que pueda con la biblioteca Python de GrabzIt. Debes pasar el Selector de CSS del elemento HTML que desea convertir a targetElement método de GrabzItDOCXOptions clase.

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

En este ejemplo, deseamos capturar todo el contenido en el lapso que tiene la identificación de Article, por lo tanto, pasamos esto a GrabzIt API como se muestra a continuación.

from GrabzIt import GrabzItDOCXOptions
from GrabzIt import GrabzItClient

grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzItDOCXOptions.GrabzItDOCXOptions()
options.targetElement = "#Article"

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