Giter Site home page Giter Site logo

iqquee / webshot Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 26 KB

webshot is a free website screenshotting library in golang

License: MIT License

Go 100.00%
go screenshot screenshot-library webshot website-screenshot website-screenshot-capturer websitescreenshot

webshot's Introduction

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)
}

webshot's People

Contributors

iqquee avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.