This is a Golang Wikipedia API wrapper - The Golang module that makes it easy to access and parse data from Wikipedia. You can use this module to crawl data for your data warehouse or use it for your "Know-it-all" AI Chatbot.
To install Go-Wiki package, you need to install Go and set your Go workspace first.
- You first need Go installed, then you can use the below Go command to install Go-wiki.
go get -u github.com/trietmn/go-wiki
- Import it in your code.
import "github.com/trietmn/go-wiki"
You can read the documentation at: https://pkg.go.dev/github.com/trietmn/go-wiki
I will update a full tutorial article on some popular blog as soon as possiple.
# assume the following codes in example.go file
$ cat example.go
package main
import (
"fmt"
"github.com/trietmn/go-wiki"
)
func main() {
// Search for the Wikipedia page title
search_result, _, err := gowiki.Search("Why is the sky blue", 3, false)
if err != nil {
fmt.Println(err)
}
fmt.Printf("This is your search result: %v\n", search_result)
// Get the page
page, err := gowiki.GetPage("Rafael Nadal", -1, false, true)
if err != nil {
fmt.Println(err)
}
// Get the content of the page
content, err := page.GetContent()
if err != nil {
fmt.Println(err)
}
fmt.Printf("This is the page content: %v\n", content)
}
# run example.go
$ go run example.go
Note: The functions below are functions that you would usually use. Read the document to see all the functions.
search_result, suggestion, err := gowiki.Search("Why is the sky blue", 3, true)
if err != nil {
fmt.Println(err)
}
fmt.Printf("Search result: %v\n", search_result)
fmt.Printf("Suggestion: %v\n", suggestion)
2. GetPage (There are multiple page methods in the Wikipedia Page Methods)
page, err := gowiki.GetPage("Rafael Nadal", -1, false, true)
if err != nil {
fmt.Println(err)
}
// Then now you can use the page methods
suggestion, err := gowiki.Suggest("nadal")
if err != nil {
fmt.Println(err)
}
fmt.Printf("Suggestion: %v\n", suggestion)
res, err := gowiki.GeoSearch(40.67693, 117.23193, -1, "", -1)
if err != nil {
fmt.Println(err)
}
fmt.Printf("Geosearch result: %v\n", res)
res, err := gowiki.GetRandom(5)
if err != nil {
fmt.Println(err)
}
fmt.Printf("Random titles: %v\n", res)
res, err := gowiki.Summary("Rafael Nadal", 5, -1, false, true)
if err != nil {
fmt.Println(err)
}
fmt.Printf("Summary: %v\n", res)
Methods | Description | Example |
---|---|---|
Equal | Check if 2 pages are equal to each other | page1.Equal(page2) |
GetContent | Get the page content | page.GetContent() |
GetHTML | Get the page HTML | page.GetHTML() |
GetRevisionID | Get revid field of a page | page.GetRevisionID() |
GetParentID | Get parentid field of a page | page.GetParentID() |
GetSummary | Get the summary of the page | page.GetSummary() |
GetImagesURL | Get all of the image URL appear in the page | page.GetImageURL() |
GetCoordinate | Get the page coordinate if exist | page.GetCoordinate() |
GetReference | Get all of the extenal links in the page | page.GetReference() |
GetLink | Get all the titles of Wikipedia page links on a page | page.GetLink() |
GetCategory | Get all of the categories of a page | page.GetCategory() |
GetSectionList | Get all of the sections of the page | page.GetSectionList() |
GetSection | Get the content of a specific section in the page | page.GetSection("History") |
MIT licensed. See the LICENSE file for full details.
Connect with me on Linkedin: https://www.linkedin.com/in/triet-m-nguyen-a94b4b20b/
- Python Wikipedia by goldsmith as inspiration.
- The Wikimedia Foundation for giving the world free access to data.