package main
import (
"fmt"
"io"
"net/http"
"regexp"
"strings"
)
/* ページのタイトル */
func gettitle(str string) string {
re := regexp.MustCompile("
`
res["img"] = ""
res["desc"] = ""
res["err"] = ""
resp, err := http.Get("https://news.mixi.jp" + url)
if err != nil {
res["err"] = "URLエラー"
fmt.Println(res["err"] + ": " + err.Error())
return res
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
bytebody, err := io.ReadAll(resp.Body)
if err != nil {
res["err"] = "内容はバイトコードとして読み込みに失敗。"
fmt.Println(res["err"])
return res
}
body, err := EUCJPToUTF8(bytebody)
if err != nil {
res["err"] = err.Error()
fmt.Println(res["err"])
return res
}
id, _ := getid(url)
res["title"] = gettitle(body)
if isarticle(url) {
if !strings.Contains(body, "newsArticle") {
res["content"] = rmebloat(body, cnf)
} else {
res["img"] = getimg(body, cnf)
res["content"] = rmbloat(id, body, cnf)
}
} else if ispublish(url) {
res["content"] = rmpbloat(body, cnf)
} else if issubcat(url) {
if strings.Contains(body, `
存在しないカテゴリです
`) {
res["content"] = rmebloat(body, cnf)
} else {
res["content"] = rmsbloat(body, cnf)
}
} else if istubayaki(url) {
if !strings.Contains(body, "quoteList") {
res["content"] = rmebloat(body, cnf)
} else {
res["content"] = rmqbloat(body, cnf)
}
} else {
if !strings.Contains(body, "注目のニュース") {
res["content"] = rmebloat(body, cnf)
} else {
res["content"] = rmcbloat(body, cnf)
}
}
res["desc"] = getdesc(res["content"])
}
return res
}