Skip to content

This is a Golang open-source module that makes it easy to access and parse data from Wikipedia (Wikipedia API wrapper)

License

Notifications You must be signed in to change notification settings

trietmn/go-wiki

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go-wiki

go report card MIT license GoDoc

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.

Contents

Instalation

To install Go-Wiki package, you need to install Go and set your Go workspace first.

  1. 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
  1. Import it in your code.
import "github.com/trietmn/go-wiki"

Documentation

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.

Quick start

# 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

Functions Examples

Note: The functions below are functions that you would usually use. Read the document to see all the functions.

1. Search

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

3. Suggest

suggestion, err := gowiki.Suggest("nadal")
if err != nil {
    fmt.Println(err)
}
fmt.Printf("Suggestion: %v\n", suggestion)

4. Geosearch

res, err := gowiki.GeoSearch(40.67693, 117.23193, -1, "", -1)
if err != nil {
    fmt.Println(err)
}
fmt.Printf("Geosearch result: %v\n", res)

5. GetRandom

res, err := gowiki.GetRandom(5)
if err != nil {
    fmt.Println(err)
}
fmt.Printf("Random titles: %v\n", res)

6. Summary

res, err := gowiki.Summary("Rafael Nadal", 5, -1, false, true)
if err != nil {
    fmt.Println(err)
}
fmt.Printf("Summary: %v\n", res)

Wikipedia Page Methods

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")

License

MIT licensed. See the LICENSE file for full details.

About me

Connect with me on Linkedin: https://www.linkedin.com/in/triet-m-nguyen-a94b4b20b/

Credit

About

This is a Golang open-source module that makes it easy to access and parse data from Wikipedia (Wikipedia API wrapper)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages