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

צלם תמונות מסך של אתר או המרת HTML לתמונות

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

צור צילומי מסך מושלמים של אתרים או המר HTML ישירות לתמונות על ידי שימוש בתכונות הבאות של ממשק ה- API של GrabzIt Python. עם זאת לפני שתתחיל לזכור את זה לאחר התקשרות אל URLToImage, HTMLToImage or FileToImage שיטות Save or SaveTo יש לקרוא לשיטה לצילום המסך.

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

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

grabzIt.URLToImage("https://www.tesla.com")
# Then call the Save or SaveTo method
grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>")
# Then call the Save or SaveTo method
grabzIt.FileToImage("example.html")
# Then call the Save or SaveTo method

פורמטים של תמונות

ה- Python API של GrabzIt יכול לצלם תמונות מסך בכמה פורמטים, כולל JPG, PNG, WEBP, BMP (8 bit, 16 bit, 24 bit או 32 bit) ו- TIFF. פורמט ברירת המחדל של צילומי מסך של תמונות הוא JPG. עם זאת איכות התמונה של JPG עשויה להיות לא מספיק טובה עבור יישומים מסוימים בנסיבות אלה, פורמט PNG מומלץ לצילומי מסך של תמונות שכן הוא נותן איזון טוב בין איכות לגודל הקובץ. הדוגמה הבאה מציגה צילום מסך שצולם בפורמט PNG.

from GrabzIt import GrabzItImageOptions
from GrabzIt import GrabzItClient

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

options = GrabzItImageOptions.GrabzItImageOptions()
options.format = "png"

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

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

options = GrabzItImageOptions.GrabzItImageOptions()
options.format = "png"

grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options)
# Then call the Save or SaveTo method
grabzIt.SaveTo("result.png")
from GrabzIt import GrabzItImageOptions
from GrabzIt import GrabzItClient

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

options = GrabzItImageOptions.GrabzItImageOptions()
options.format = "png"

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

גודל הדפדפן

גודל הדפדפן מתייחס לגודל חלון הדפדפן שישמש בעת צילום הצילום המסך ברוב המקרים זה לא צריך להיות מוגדר מכיוון שגודל ברירת המחדל של הדפדפן יספיק לכל רוב המשימות. כדי להשתמש בגודל ברירת המחדל של הדפדפן פשוט עברו 0 אל ה browserWidth ו browserHeight תכונות של GrabzItImageOptions מעמד.

שנה את גודל התמונה

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

אם ברצונך להגדיל את רוחב וגובה התמונה לגודל גדול יותר מרוחב וגובה הדפדפן, אשר כברירת מחדל הוא 1366 על ידי 728 פיקסלים, יש להגדיל את רוחב הגובה של הדפדפן כך שיתאים.

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

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

from GrabzIt import GrabzItImageOptions
from GrabzIt import GrabzItClient

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

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

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

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

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

grabzIt.HTMLToImage("<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 GrabzItImageOptions
from GrabzIt import GrabzItClient

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

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

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

צילום מסך באורך מלא

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

from GrabzIt import GrabzItImageOptions
from GrabzIt import GrabzItClient

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

options = GrabzItImageOptions.GrabzItImageOptions()
options.browserHeight = -1
options.width = -1
options.height = -1

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

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

options = GrabzItImageOptions.GrabzItImageOptions()
options.browserHeight = -1
options.width = -1
options.height = -1

grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options)
# Then call the Save or SaveTo method
grabzIt.SaveTo("result.jpg")
from GrabzIt import GrabzItImageOptions
from GrabzIt import GrabzItClient

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

options = GrabzItImageOptions.GrabzItImageOptions()
options.browserHeight = -1
options.width = -1
options.height = -1

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

אתה יכול גם להחזיר תמונות ממוזערות שאינן קצוצות, אך היזהר מכיוון שיכול ליצור תמונות גדולות. לשם כך העבירו -1 ל- height ו / או width תכונות. הממד שמועבר -1 לא ייחתך.

from GrabzIt import GrabzItImageOptions
from GrabzIt import GrabzItClient

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

options = GrabzItImageOptions.GrabzItImageOptions()
options.width = -1
options.height = -1

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

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

options = GrabzItImageOptions.GrabzItImageOptions()
options.width = -1
options.height = -1

grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options)
# Then call the Save or SaveTo method
grabzIt.SaveTo("result.jpg")
from GrabzIt import GrabzItImageOptions
from GrabzIt import GrabzItClient

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

options = GrabzItImageOptions.GrabzItImageOptions()
options.width = -1
options.height = -1

grabzIt.FileToImage("example.html", options)
# Then call the Save or SaveTo method
grabzIt.SaveTo("result.jpg")
שים לב שאין רוחב דפדפן באורך מלא!

השימוש בערכים המיוחדים הללו פירושו שתוכלו ליצור צילום מסך המהווה גרסה בקנה מידה מלא של כל דף האינטרנט אם תרצו!

צלם תמונת מסך של אלמנט עמוד

GrabzIt מאפשר לך לצלם צילום מסך של אלמנט HTML, כגון div or span לתייג ולתפוס את כל תוכנו. לשם כך יש לציין את אלמנט ה- HTML שברצונך למסך למסך בורר CSS.

...
<div id="features">
	<img src="http://www.example.com/race.jpg"/><h3>Car Race Tommorow</h3>
</div>
...

עבור הדוגמה למטה אנו נבחר את ה- div עם המזהה "features" ונציג אותו כתמונת JPEG 250 x 250px.

from GrabzIt import GrabzItImageOptions
from GrabzIt import GrabzItClient

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

# The 250 parameters indicates that image should be sized to 250 x 250 px
options = GrabzItImageOptions.GrabzItImageOptions()
options.width = 250
options.height = 250
options.format = "jpg"
options.targetElement = "#features"

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

הדוגמה הבאה מצולמת צילום מסך נוסף של ה- div "תכונות" אך הפעם מוציא תמונת JPEG בגודל המדויק של ה- div.

from GrabzIt import GrabzItImageOptions
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 = "#features"

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