Skip to content
/ webshot Public

webshot is a free website screenshotting library in golang

License

Notifications You must be signed in to change notification settings

iqquee/webshot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

webshot

webshot is a free website screenshotting library in golang

Get Started

In other to use this package, you need to first install tesseract on your machine and then download GeckoDriver for your os from https://github.com/mozilla/geckodriver/releases.

NOTE: The browser used in this package by default is firefox. Kindly install firefox if you don't have it on your machine already.

Installation

This package can be installed by using the go command below.

go get github.com/iqquee/webshot

Quick start

# assume the following codes in example.go file
$ touch example.go
# open the just created example.go file in the text editor of your choice

Screenshot

Screenshot is the default screenshotter which can take the screenshot of webpages

package main

import (
	"fmt"
	"os"

	"github.com/iqquee/webshot"
)

func main() {
	config := webshot.NewConfig{
		Address:     "http://localhost",
		Port:        4444, // you can change accordingly to which ever port you wish
		BrowserName: webshot.FirefoxBrowser,
		DebugMode:   true, // set to true if you want to get the logs
		DriverPath:  "", // your gekodriver path goes in here
	}

	driver, err := webshot.NewWebshot(config)
	if err != nil {
		fmt.Println(err)
		return
	}

	url := "https://google.com"

	byteImage, err := driver.Screenshot(url)
	if err != nil {
		fmt.Println(err)
		return
	}

	fileName := "screenshot" + ".png"
	pngData, _ := os.Create(fileName)
	pngData.Write([]byte(byteImage))
}

ImageProcessing

ImageProcessing does the optical character recognition(OCR)

This method processess an image and returns the text in that image in a .txt file.

package main

import (
	"fmt"

	"github.com/iqquee/webshot"
)

func main() {

    filePath := ""
    fileName := ""
	if err := webshot.ImageProcessing(filePath, fileName); err != nil {
		fmt.Println("Image processing err: \n", err)
		return
	}
}

Extend

Extend allow you to use use all of the functionalities provided by selenium

You can use the Extend() to pretty much do whatever you wish as long as it's a functionality selenium supports.

package main

import (
	"fmt"

	webshot "github.com/iqquee/webshot"
)

func main() {
    config := webshot.NewConfig{
		Address:     "http://localhost",
		Port:        4444, // you can change accordingly to which ever port you wish
		BrowserName: webshot.FirefoxBrowser,
		DebugMode:   true, // set to true if you want to get the logs
		DriverPath:  "", // your gekodriver path goes in here
	}

	driver, err := webshot.NewWebshot(config)
	if err != nil {
		fmt.Println(err)
		return
	}

	service := driver.Extend()
	imgBytes, err := service.Screenshot()
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(imgBytes)
}

Releases

No releases published

Packages

No packages published

Languages