link

package
v0.0.0-...-789b534 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: MIT Imports: 5 Imported by: 0

README

For each extracted link this program returns a data structure Link which includes both the href, as well as the text inside the link. Any HTML inside of the link is stripped out, along with any extra whitespace including newlines, back-to-back spaces, etc.

Links will be nested in different HTML elements, and it is very possible that you will have to deal with HTML similar to code below.

<a href="/dog">
  <span>Something in a span</span>
  Text not in a span
  <b>Bold text!</b>
</a>

In situations like these, we want to get output that looks roughly like:

Link{
  Href: "/dog",
  Text: "Something in a span Text not in a span Bold text!",
}

Usage

go run main.go <filename>

Response would be something like this:

[{/other-page A link to another page} {/second-page A link to second page}]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Link struct {
	Href string
	Text string
}

Link stores "href" attribute as well as text within the <a> tag

func Parse

func Parse(r io.Reader) ([]Link, error)

Parse will take in an HTML document and will return a slice of links parsed from it.

Jump to

Keyboard shortcuts

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