sydsvenskan

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: MIT Imports: 8 Imported by: 0

README

sydsvenskan

Sydsvenskan is a small Golang module for performing a search at sydsvenskan.se

Documentation

Overview

Package sydsvenskan searches sydsvenskan.se

Index

Constants

View Source
const (
	ResultsPath    = "//div[starts-with(@class, 'teaser ')]"
	LinkPath       = "//a[contains(@class, 'teaser__text-link')]/@href"
	HeadingPath    = "//h2[contains(@class, 'teaser__heading')]"
	PreamblePath   = "//h2[contains(@class, 'teaser__heading')]/following-sibling::div[contains(@class, 'teaser__preamble')]"
	PremiumPath    = ".[contains(@class, 'teaser--premium')]"
	ImagePath      = "//img/@data-src"
	PaginationPath = "//*[starts-with(@class, 'pagination')]/a[contains(@class, 'pagination__link--next')]/@href"
)

XPaths for getting search result data

View Source
const SearchURLTemplate = "https://www.sydsvenskan.se/sok?q=%s"

SearchURLTemplate is the URL for the search query

Variables

View Source
var BaseURL, _ = url.Parse("https://www.sydsvenskan.se/")

BaseURL is the URL base for all URLs

View Source
var DatePathSegment = regexp.MustCompile(`\d\d\d\d-\d\d-\d\d`)

DatePathSegment is the regexp for date in the URL Path

Functions

func Search(q string) chan Teaser

Search sends a query and returns result iterator (channel)

Types

type Teaser added in v1.0.2

type Teaser struct {
	Title     string //The teaser heading
	Preamble  string
	URL       string
	Image     string
	IsPremium bool
	Published time.Time
	Query     string    //The search query used to get the teaser
	LastSeen  time.Time //When the teaser was seen at the site
}

Teaser is a search result

func (*Teaser) ParseImage added in v1.0.3

func (t *Teaser) ParseImage(node *html.Node)

ParseImage extracts the image URL

func (*Teaser) ParsePreamble added in v1.0.3

func (t *Teaser) ParsePreamble(node *html.Node)

ParsePreamble extract the text immediately after the heading

func (*Teaser) ParsePremium added in v1.0.3

func (t *Teaser) ParsePremium(node *html.Node)

ParsePremium extracts premium flag

func (*Teaser) ParseTitle added in v1.0.3

func (t *Teaser) ParseTitle(node *html.Node)

ParseTitle extract the title

func (*Teaser) ParseURL added in v1.0.3

func (t *Teaser) ParseURL(node *html.Node)

ParseURL extract URL and Published date

Jump to

Keyboard shortcuts

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