model

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LookupTable = [...]string{
	"//*[@id=\"business-unit-title\"]/h1/span[1]",
	"//*[@id=\"business-unit-title\"]/span[1]/span",
	"//*[@id=\"business-unit-title\"]/div/div/p",
	"//*[@id=\"business-unit-title\"]/div/div/div/img",
}

Functions

This section is empty.

Types

type Result

type Result struct {
	Company string // The company name
	Reviews struct {
		Total string // Total amount reviews
		Text  string // Description text
	}
	ImageSRC string // The SVG of the star rate graphical vector
}

func Parse

func Parse(body io.ReadCloser) (*Result, error)

Parse parses the HTML content from the given io.ReadCloser and returns a Result struct and an error.

It takes a parameter `body` of type `io.ReadCloser` which represents the HTML content.

The function first parses the HTML content using the `htmlquery.Parse` function. If there is an error during the parsing, it returns the error.

Then, it initializes an empty `Result` struct.

Next, it iterates over the `LookupTable` and performs different operations based on the index.

- If the index is 0, it sets the `Company` field of the `Result` struct to the inner text of the parsed node. - If the index is 1, it sets the `Text` field of the `Reviews` struct to the inner text of the parsed node. - If the index is 2, it sets the `Total` field of the `Reviews` struct to the inner text of the parsed node. - If the index is 3, it sets the `ImageSRC` field of the `Result` struct to the value of the "src" attribute of the parsed node.

Finally, it returns a pointer to the `Result` struct and a `nil` error.

func (*Result) GetCompanyName

func (r *Result) GetCompanyName() string

GetCompanyName returns the name of the company.

This function takes no parameters and returns a string representing the name of the company.

func (*Result) GetReviewsText

func (r *Result) GetReviewsText() string

GetReviewsText returns the text of the reviews.

It does not take any parameters. It returns a string.

func (*Result) GetTotalReviews

func (r *Result) GetTotalReviews() string

GetTotalReviews returns the total number of reviews.

It does not take any parameters. It returns a string.

Jump to

Keyboard shortcuts

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