Web Yakalama ve Dönüştürme Araçları

Web Sitesi Ekran Görüntülerini Yakala veya HTML'yi Görüntülere Dönüştür

Ruby API

Aşağıdaki özellikleri kullanarak web sayfalarının daha iyi görüntü ekran görüntülerini alın veya HTML'yi görüntülere dönüştürün GrabzİT'in Ruby API'si. Ancak başlamadan önce aradıktan sonra bunu hatırlayın. url_to_image, html_to_image or file_to_image yöntemler save or save_to görüntüyü oluşturmak için yöntem çağrılmalıdır.

Temel Seçenekler

Bir web sayfasının ekran görüntüsünü almak için yalnızca bir parametre gereklidir veya HTML'yi dönüştür into bir görüntü aşağıdaki örnekte gösterildiği gibi.

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

Görüntü Biçimleri

GrabzIt’ın Ruby API’sı JPG, PNG, WEBP, BMP (8 bit, 16 bit, 24 bit veya 32 bit) ve TIFF gibi çeşitli formatlarda görüntü ekran görüntülerini alabilir. Görüntü ekran görüntüleri için varsayılan format JPG'dir. Bununla birlikte, bir JPG görüntünün kalitesi bu durumlarda bazı uygulamalar için yeterince iyi olmayabilir, çünkü PNG formatı görüntü ekran görüntüleri için önerilir, çünkü kalite ve dosya boyutu arasında iyi bir denge sağlar. Aşağıdaki örnek, PNG formatı kullanılarak alınmış bir görüntü ekran görüntüsünü gösterir.

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

options = GrabzIt::ImageOptions.new()
options.format = "png"

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

options = GrabzIt::ImageOptions.new()
options.format = "png"

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

options = GrabzIt::ImageOptions.new()
options.format = "png"

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

Tarayıcı boyutu

Tarayıcı boyutu, çoğu durumda ekran görüntüsünü alırken kullanılacak tarayıcı penceresinin boyutuna işaret eder. Bu, varsayılan tarayıcı boyutunun ayarlanması gerekmediğinden tüm görevlerin tümü için yeterli olacaktır. Tarayıcı boyutunu ayarlamak için browserWidth ve browserHeight yöntemleri ImageOptions sınıf.

Görüntü Boyutunu Değiştir

Görüntünün boyutunu değiştirmek kolaydır, görüntüyü bozmadan yapmak biraz zordur. Tüm süreci kolaylaştırmak için bunu kullanmanızı öneririz. basit resim boyut hesaplayıcısı.

Görüntü genişliğini ve yüksekliğini, varsayılan olarak 1366 piksel olarak 728 olan tarayıcı genişliğinden ve yüksekliğinden daha büyük bir boyuta çıkarmak istiyorsanız, tarayıcı genişliğinin ve yüksekliğinin de eşleşmesi için artırılması gerekir.

Özel tanımlayıcı

Özel bir tanımlayıcıyı görüntü Aşağıda gösterilen yöntemlerde bu değer daha sonra GrabzIt Ruby işleyicinize döndürülür. Örneğin, bu özel tanımlayıcı, bir ekran görüntüsünün belirli bir veritabanı kaydı ile ilişkilendirilmesine izin veren bir veritabanı tanıtıcısı olabilir.

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

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

grabzItClient.url_to_image("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::ImageOptions.new()
options.customId = "123456"

grabzItClient.html_to_image("<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::ImageOptions.new()
options.customId = "123456"

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

Tam Boy Ekran Görüntüsü

GrabzIt, web sayfasına bir -1 aktarmanız gereken tam bir ekran görüntüsünün tamamını web sayfasının tamamında çekmenizi sağlar. browserHeight yöntem. Görüntünün, tarayıcının boyutuyla eşleştiğinden emin olmak için, height ve width Öznitellikler.

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

options = GrabzIt::ImageOptions.new()
options.browserHeight = -1
options.width = -1
options.height = -1

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

options = GrabzIt::ImageOptions.new()
options.browserHeight = -1
options.width = -1
options.height = -1

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

options = GrabzIt::ImageOptions.new()
options.browserHeight = -1
options.width = -1
options.height = -1

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

Ayrıca kırpılmayan küçük resimleri de döndürebilirsiniz, ancak bunun büyük görüntüler oluşturabildiğine dikkat edin. Bunu yapmak için: height ve / veya width yöntemleri. -1'ten geçen boyut kırpılmayacak.

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

options = GrabzIt::ImageOptions.new()
options.width = -1
options.height = -1

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

options = GrabzIt::ImageOptions.new()
options.width = -1
options.height = -1

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

options = GrabzIt::ImageOptions.new()
options.width = -1
options.height = -1

grabzItClient.file_to_image("example.html", options)
# Then call the save or save_to method
grabzItClient.save_to("result.jpg")
Tam boy tarayıcı genişliği olmadığını unutmayın!

Bu özel değerleri kullanmak, isterseniz tüm web sayfasının tam ölçekli bir ekran görüntüsü oluşturabileceğiniz anlamına gelir!

Sayfa Öğesinin Ekran Görüntüsü Al

GrabzIt, bir HTML öğesinin ekran görüntüsünü örneğin div or span etiketleyin ve tüm içeriğini yakalayın. Bunu yapmak için, ekran görüntüsünü almak istediğiniz HTML öğesi bir CSS seçici.

...
<div id="features">
	<img src="http://www.example.com/rocket.jpg"/><h3>Rocket Launch Next Week</h3>
</div>
...

Aşağıdaki örnekte, "özellik" kimliğine sahip olan div'yi seçeceğiz ve onu bir 250 x 250px JPEG görüntüsü olarak göstereceğiz.

grabzItClient = GrabzIt::Client.new("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 = GrabzIt::ImageOptions.new()
options.width = 250
options.height = 250
options.format = "jpg"
options.targetElement = "#features"

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

Bir sonraki örnek "features" div'in başka bir ekran görüntüsünü alıyor ancak bu sefer div'in tam boyutunda olan bir JPEG görüntü çıktısı veriyor.

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

# The -1 indicates that image should not be cropped
options = GrabzIt::ImageOptions.new()
options.width = 250
options.height = 250
options.format = "jpg"
options.targetElement = "#features"
options.browserHeight = -1

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