screenshotmachine vb
1.0.0
本demo展示了如何使用Visual Basic编程语言调用在线截图机API。
首先,您需要在 www.screenshotmachine.com 网站上创建一个免费/高级帐户。注册后,您将在您的用户个人资料中看到您的客户密钥。这里还保留了秘密短语。当您的 API 调用是从公开网站调用时,请始终使用秘密短语。
在脚本中设置您的客户密钥和秘密短语(如果需要):
Dim customerKey As String = "PUT_YOUR_CUSTOMER_KEY_HERE"
Dim secretPhrase As String = "" REM leave secret phrase empty, If Not needed
设置附加选项以满足您的需求:
Dim options As New Dictionary( Of String , String )
REM mandatory parameter
options.Add( "url" , "https://www.google.com" )
REM all next parameters are optional, see our website screenshot API guide for more details
options.Add( "dimension" , "1366x768" ) REM Or "1366xfull" For full length screenshot
options.Add( "device" , "desktop" )
options.Add( "format" , "png" )
options.Add( "cacheLimit" , "0" )
options.Add( "delay" , "200" )
options.Add( "zoom" , "100" )
有关选项的更多信息可以在我们的网站屏幕截图 API 中找到。
Imports System.Net
Public Class Client
Public Shared Sub Main(args() As String )
Dim customerKey As String = "PUT_YOUR_CUSTOMER_KEY_HERE"
Dim secretPhrase As String = "" REM leave secret phrase empty, If Not needed
Dim options As New Dictionary( Of String , String )
REM mandatory parameter
options.Add( "url" , "https://www.google.com" )
REM all next parameters are optional, see our website screenshot API guide for more details
options.Add( "dimension" , "1366x768" ) REM or "1366xfull" for full length screenshot
options.Add( "device" , "desktop" )
options.Add( "format" , "png" )
options.Add( "cacheLimit" , "0" )
options.Add( "delay" , "200" )
options.Add( "zoom" , "100" )
Dim sm As ScreenshotMachine = New ScreenshotMachine(customerKey, secretPhrase)
Dim apiUrl As String = sm.GenerateScreenshotApiUrl(options)
REM use final apiUrl where needed
Console.WriteLine(apiUrl)
End Sub
End Class
生成的apiUrl
链接可以放置在<img>
标记中或稍后在您的业务逻辑中使用。
如果您需要将捕获的屏幕截图存储为图像,只需调用:
Dim apiUrl As String = sm.GenerateScreenshotApiUrl(options)
REM or save screenshot directly
Dim client As New WebClient()
Dim output As String = "output.png"
client.DownloadFile(apiUrl, output)
Console.WriteLine( "Screenshot saved as " + output)
捕获的屏幕截图将作为output.png
文件保存在当前目录中。
设置 PDF 选项:
Dim options As New Dictionary( Of String , String )
REM mandatory parameter
options.Add( "url" , "https://www.google.com" )
REM all next parameters are optional, see our website to PDF API guide for more details
options.Add( "paper" , "letter" )
options.Add( "orientation" , "portrait" )
options.Add( "media" , "print" )
options.Add( "bg" , "nobg" )
options.Add( "delay" , "2000" )
options.Add( "scale" , "50" )
有关选项的更多信息可以在我们的 PDF API 网站中找到。
Imports System.Net
Public Class ClientPdf
Public Shared Sub Main(args() As String )
Dim customerKey As String = "PUT_YOUR_CUSTOMER_KEY_HERE"
Dim secretPhrase As String = "" REM leave secret phrase empty, If Not needed
Dim options As New Dictionary( Of String , String )
REM mandatory parameter
options.Add( "url" , "https://www.google.com" )
REM all next parameters are optional, see our website to PDF API guide for more details
options.Add( "paper" , "letter" )
options.Add( "orientation" , "portrait" )
options.Add( "media" , "print" )
options.Add( "bg" , "nobg" )
options.Add( "delay" , "2000" )
options.Add( "scale" , "50" )
Dim sm As ScreenshotMachine = New ScreenshotMachine(customerKey, secretPhrase)
Dim pdfApiUrl As String = sm.GeneratePdfApiUrl(options)
REM save PDF file
Dim client As New WebClient()
Dim output As String = "output.pdf"
client.DownloadFile(pdfApiUrl, output)
Console.WriteLine( "PDF saved as " + output)
End Sub
End Class
捕获的 PDF 将作为output.pdf
文件保存在当前目录中。
麻省理工学院许可证 (MIT)