scriptsources

package module
v0.0.0-...-43d0048 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2015 License: MIT Imports: 2 Imported by: 0

README

Package scriptsources is a simple utility that extracts resources referenced inside of HTML script tags. Given a URL, it'll retrieve the page and comb through the body of the response finding all resources specified in the <script> tags' src attributes.

GoDoc Build Status

Usage

package main

import (
	"github.com/jboursiquot/scriptsources"

	"fmt"
	"net/http"
)

func main() {
	resp, err := http.Get("http://jboursiquot.com")
	checkErr(err)
	defer resp.Body.Close()

	resources := scriptsources.ExtractResources(resp.Body)

	fmt.Println(resources)
}

func checkErr(err error) {
	if err != nil {
		panic(err)
	}
}

Your output should be something like this:

[http://jboursiquot.com/wp-includes/js/jquery/jquery.js?ver=1.11.3 http://jboursiquot.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1 http://jboursiquot.com/wp-content/themes/zeebizzcard/includes/js/jquery.cycle.all.min.js?ver=4.3.1 http://jboursiquot.com/wp-content/plugins/google-analyticator/external-tracking.min.js?ver=6.4.9 //platform.twitter.com/oct.js]

Enjoy.

Documentation

Overview

Package scriptsources searches through HTML for script tags and returns the URLs found in the src attributes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractResources

func ExtractResources(body io.Reader) (urls []string)

ExtractResources takes an io.Reader (such as an http response body), parses and returns the resource references in the script tags.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL