mirror of
https://code.dumpstack.io/tools/wi.git
synced 2024-11-22 19:13:01 +00:00
Add base implementation
This commit is contained in:
parent
90fba72f62
commit
53c54d375c
56
main.go
Normal file
56
main.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user