Add base implementation

This commit is contained in:
Mikhail Klementyev 2016-07-20 01:08:19 +03:00
parent 90fba72f62
commit 53c54d375c

56
main.go Normal file
View File

@ -0,0 +1,56 @@
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"github.com/jaytaylor/html2text"
"golang.org/x/net/html/charset"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
var (
url = kingpin.Flag("url", "Url").String()
)
func main() {
kingpin.Parse()
client := &http.Client{}
req, err := http.NewRequest("GET", *url, nil)
if err != nil {
log.Fatalln(err)
}
req.Header.Set("User-Agent", "Wi 0.0")
resp, err := client.Do(req)
if err != nil {
log.Fatalln(err)
}
defer resp.Body.Close()
utf8, err := charset.NewReader(resp.Body, resp.Header.Get("Content-Type"))
if err != nil {
fmt.Println("Encoding error:", err)
return
}
body, err := ioutil.ReadAll(utf8)
if err != nil {
fmt.Println("IO error:", err)
return
}
text, err := html2text.FromString(string(body))
if err != nil {
panic(err)
}
fmt.Println(text)
}