כלים ללכידה ולהמרה של האינטרנט

המרת כתובות URL ו- HTML ל- DOCX

ממשק API של פייתון

הוספת היכולת להמיר HTML או דפי אינטרנט into מסמכי Word ליישום שלך מעולם לא היו קלים יותר ממשק ה- API של GrabzIt Python. עם זאת לפני שתתחיל לזכור את זה לאחר התקשרות אל URLToDOCX, HTMLToDOCX or FileToDOCX שיטות Save or SaveTo יש לקרוא לשיטה ליצירת DOCX בפועל.

אפשרויות בסיסיות

לכידת דפי אינטרנט כאשר DOCX ממיר את כל דף האינטרנט intoa מסמך Word שיכול להכיל עמודים רבים. כדי להמיר דף אינטרנט נדרש פרמטר אחד בלבד intמסמך Word או ל- המרת HTML ל- DOCX כפי שמוצג בדוגמאות שלהלן.

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

מזהה מותאם אישית

אתה יכול להעביר מזהה מותאם אישית אל ה- DOCX שיטות כמוצג להלן, ערך זה מוחזר לאחר מכן למטפל GrabzIt Python שלך. לדוגמה, מזהה מותאם אישית זה יכול להיות מזהה בסיס נתונים, המאפשר לשייך מסמך 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.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")

כותרות עליונות ותחתונות

כדי להוסיף כותרת עליונה או כותרת תחתונה למסמך Word אתה יכול לבקש שתרצה להחיל מסוים תבנית ל- DOCX שנוצר. תבנית זו חייבת להיות saved מראש ופרט את תוכן הכותרת העליונה התחתונה יחד עם כל משתנים מיוחדים. בקוד הדוגמה למטה המשתמש משתמש בתבנית שהם יצרו בשם "התבנית שלי".

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")

המר אלמנט HTML ל- DOCX

אם ברצונך להמיר אלמנט HTML כגון div או span ישירות intoa מסמך Word שאתה יכול עם ספריית Python של GrabzIt. עליך לעבור את בורר CSS של אלמנט ה- HTML שברצונך להמיר ל- targetElement שיטת GrabzItDOCXOptions מעמד.

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

בדוגמה זו ברצוננו ללכוד את כל התוכן בטווח שיש לו מזהה Articleלכן אנו מעבירים זאת ל- API של GrabzIt כמוצג להלן.

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")