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

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

ממשק API של רובי

הוספת היכולת להמיר HTML או דפי אינטרנט into מסמכי Word ליישום שלך מעולם לא היו קלים יותר ממשק API רובי של GrabzIt. עם זאת לפני שתתחיל לזכור את זה לאחר התקשרות אל url_to_docx, html_to_docx or file_to_docx שיטות save or save_to יש לקרוא לשיטה ליצירת DOCX בפועל.

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

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

grabzItClient.url_to_docx("https://www.tesla.com")
# Then call the save or save_to method
grabzItClient.html_to_docx("<html><body><h1>Hello World!</h1></body></html>")
# Then call the save or save_to method
grabzItClient.file_to_docx("example.html")
# Then call the save or save_to method

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

אתה יכול להעביר מזהה מותאם אישית אל ה- DOCX שיטות כמוצג להלן, ערך זה מוחזר לאחר מכן למטפל GrabzIt Ruby שלך. לדוגמה, מזהה מותאם אישית זה יכול להיות מזהה בסיס נתונים, המאפשר לשייך מסמך DOCX לרשומת מסד נתונים מסוימת.

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.customId = "123456"

grabzItClient.url_to_docx("https://www.tesla.com", options)
# Then call the save method
grabzItClient.save("http://www.example.com/handler/index")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.customId = "123456"

grabzItClient.html_to_docx("<html><body><h1>Hello World!</h1></body></html>", options)
# Then call the save method
grabzItClient.save("http://www.example.com/handler/index")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.customId = "123456"

grabzItClient.file_to_docx("example.html", options)
# Then call the save method
grabzItClient.save("http://www.example.com/handler/index")

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

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

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.templateId = "my template"

grabzItClient.url_to_docx("https://www.tesla.com", options)
# Then call the save or save_to method
grabzItClient.save_to("result.docx")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.templateId = "my template"

grabzItClient.html_to_docx("<html><body><h1>Hello World!</h1></body></html>", options)
# Then call the save or save_to method
grabzItClient.save_to("result.docx")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.templateId = "my template"

grabzItClient.file_to_docx("example.html", options)
# Then call the save or save_to method
grabzItClient.save_to("result.docx")

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

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

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

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

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::DOCXOptions.new()
options.targetElement = "#Article"

grabzItClient.url_to_docx("http://www.bbc.co.uk/news", options)
# Then call the save or save_to method
grabzItClient.save_to("result.docx")