kkdai / LINE-Bot-ChatSummarizer

Use ChatGPT to summarize your group chat as a chat summarizer with the LINE Bot Chat Summarizer.
Apache License 2.0
56 stars 39 forks source link

支援網路文章摘要 #32

Open kkdai opened 1 year ago

kkdai commented 1 year ago

給定一個網址 抓取該網址全部文字內容 透過 ChatGPT 給出摘要

kkdai commented 1 year ago

refer code

package main

import (
    "fmt"
    "net/http"
    "golang.org/x/net/html"
    "strings"
)

func main() {
    url := "https://www.example.com"

    resp, err := http.Get(url)
    if err != nil {
        fmt.Println("Error retrieving the URL:", err)
        return
    }
    defer resp.Body.Close()

    if resp.StatusCode != http.StatusOK {
        fmt.Println("Error status code:", resp.StatusCode)
        return
    }

    doc, err := html.Parse(resp.Body)
    if err != nil {
        fmt.Println("Error parsing HTML:", err)
        return
    }

    var textContent func(*html.Node)
    textContent = func(n *html.Node) {
        if n.Type == html.TextNode {
            text := strings.TrimSpace(n.Data)
            if text != "" {
                fmt.Println(text)
            }
        }
        for c := n.FirstChild; c != nil; c = c.NextSibling {
            textContent(c)
        }
    }
    textContent(doc)
}