goodquotes

package module
v0.0.0-...-3310434 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

README

📚 GoodQuotes 📚

A Go package for scraping quotes from Goodreads.

Installation

To install GoodQuotes, you can use go get. Run the following command:

go get -u github.com/Mixtre/goodquotes

Usage

Scraping Quotes

You can use the Quotes function to scrape quotes for a specific query.

package main

import (
	"fmt"

	"github.com/Mixtre/goodquotes"
)

func main() {
	// Example: Scraping quotes for a specific query with default page (first page)
	query := "inspiration"
	data := goodquotes.Quotes(query, 0)

	// Printing the scraped data
	for i, quote := range data.Quotes {
		fmt.Println("Quote", i+1, ":")
		fmt.Println("Text:", quote.TextQuote)
		fmt.Println("Author:", quote.Author)
		fmt.Println("Tags:", quote.Tags)
		fmt.Println("Likes:", quote.Likes)
		fmt.Println()
	}
}

Checking for More Pages

You can check if there are more pages available for a query by examining the data.Pages field. If there are additional pages, you can make subsequent requests to scrape quotes from those pages.

package main

import (
	"fmt"

	"github.com/Mixtre/goodquotes"
)

func main() {
	// Example: Checking for more pages and scraping quotes from additional pages
	query := "inspiration"
	data := goodquotes.Quotes(query, 0)

	fmt.Println("Total Pages: ",data.Pages)

	// Checking if there are more pages
	if data.Pages > 1 {
		// Scraping quotes from page 2
		page := 2
		data = goodquotes.Quotes(query, page)

		// Printing the scraped data from page 2
		for i, quote := range data.Quotes {
			fmt.Println("Quote", i+1, ":")
			fmt.Println("Text:", quote.TextQuote)
			fmt.Println("Author:", quote.Author)
			fmt.Println("Tags:", quote.Tags)
			fmt.Println("Likes:", quote.Likes)
			fmt.Println()
		}
	} else {
		fmt.Println("No more pages available.")
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Quote

type Quote struct {
	TextQuote string
	Author    string
	Tags      []string
	Likes     uint64
}

type ScrapedData

type ScrapedData struct {
	Name   string
	Pages  uint64
	Quotes []Quote
}

func Quotes

func Quotes(query string, page int) ScrapedData

Jump to

Keyboard shortcuts

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