A Go package for scraping quotes from Goodreads.
To install GoodQuotes, you can use go get
. Run the following command:
go get -u github.com/Mixtre/goodquotes
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()
}
}
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.")
}
}