Skip to content

Commit

Permalink
replace v2ex to douban
Browse files Browse the repository at this point in the history
  • Loading branch information
grj1046 committed May 14, 2021
1 parent 8445000 commit 5202dc6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ <h6>贴吧热门讨论</h6>

<div class="row">
<div class="col-sm-6">
<h6>V2EX热帖</h6>
<h6>豆瓣热帖</h6>
<div class="row-col">
{{ range $key, $val := . }}
{{ if eq $val.FileName "vsite.json" }}
{{ if eq $val.FileName "douban.json" }}
{{ range $index, $model := $val.Content }}
{{ if lt $index 10 }}
<a target="_blank" href="{{$model.Url}}" id="baidusj{{$index}}" class="list-group-item list-group-item-action">
Expand All @@ -156,7 +156,7 @@ <h6>V2EX热帖</h6>
{{ end }}
{{ end }}
<div class="more">
<a target="_blank" href="https://www.v2ex.com/?tab=hot" id="vsite" class="list-group-item list-group-item-action">more &gt;&gt;</a>
<a target="_blank" href="https://www.douban.com/group/explore" id="douban" class="list-group-item list-group-item-action">more &gt;&gt;</a>
</div>
</div>
</div>
Expand Down Expand Up @@ -186,7 +186,7 @@ <h6>知乎热榜</h6>
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
//var siteArray = ["baidusj", "baidurd", "weibo", "tieba", "vsite", "zhihu"];
//var siteArray = ["baidusj", "baidurd", "weibo", "tieba", "douban", "zhihu"];
$(function () {
var page = "hotspot";
$.getJSON(page, function (data_all) {
Expand Down
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -94,6 +95,10 @@ func getGoquryDocument(weburl string) (*goquery.Document, error) {
}
client := &http.Client{Transport: tr}
request, _ := http.NewRequest(http.MethodGet, weburl, nil)
request.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
u, _ := url.Parse(weburl)
request.Header.Add("Host", u.Host)
request.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36")
response, err := client.Do(request)
if err != nil {
return nil, errors.New("NewRequest: " + err.Error())
Expand Down Expand Up @@ -224,8 +229,8 @@ func GetHotSiteModel() []HotSiteModel {
SiteIsUTF8Encode: false, profixURL: "https://s.weibo.com"},
{WebURL: "http://tieba.baidu.com/hottopic/browse/topicList?res_type=1", FileName: "tieba.json", selector: "a.topic-text",
SiteIsUTF8Encode: false, profixURL: ""},
{WebURL: "https://www.v2ex.com/?tab=hot", FileName: "vsite.json", selector: "span.item_title a",
SiteIsUTF8Encode: false, profixURL: "https://www.v2ex.com"},
{WebURL: "https://www.douban.com/group/explore", FileName: "douban.json", selector: "div.channel-item h3 a",
SiteIsUTF8Encode: false, profixURL: ""},
}
return sites
}
Expand Down

0 comments on commit 5202dc6

Please sign in to comment.