package main
import (
"fmt"
"net/http"
"github.com/bitly/go-simplejson"
"io/ioutil"
"os"
"encoding/csv"
)
func check(e error) {
if e!=nil{
fmt.Println(e)
}
}
func main() {
news,_:=os.OpenFile("News.csv",os.O_WRONLY|os.O_CREATE, os.ModePerm)
defer news.Close()
w:=csv.NewWriter(news)
url:="http://www.xusong.com/api/NEWS/getNews.json?page=1&pageSize=10"
json,e:=http.Get(url)
check(e)
body,e:=ioutil.ReadAll(json.Body)
res,_:=simplejson.NewJson([]byte(body))
for i:=0;i<20;i++{
cur:= res.Get("result").GetIndex(i)
addTime,_:= cur.Get("addTime").String()
content,_:=cur.Get("content").String()
title,_:=cur.Get("title").String()
id,_:=cur.Get("id").String()
url:= "http://www.xusong.com/news/"+id
w.Write([]string{title,content,url,addTime})
fmt.Println("写入",i)
}
activity,_:=os.OpenFile("activity.csv",os.O_WRONLY|os.O_CREATE, os.ModePerm)
defer activity.Close()
ws:=csv.NewWriter(activity)
urls:="http://www.xusong.com/api/NEWS/getCalendarList.json?page=1&pageSize=10"
jsons,e:=http.Get(urls)
check(e)
bodys,e:=ioutil.ReadAll(jsons.Body)
ress,_:=simplejson.NewJson([]byte(bodys))
for i:=0;i<10;i++{
cur:= ress.Get("result").Get("activityInfo").GetIndex(i)
addTime,_:= cur.Get("endTime").String()
content,_:=cur.Get("content").String()
title,_:=cur.Get("title").String()
id,_:=cur.Get("id").String()
url:= "http://www.xusong.com/calendars/"+id
ws.Write([]string{title,content,url,addTime})
fmt.Println("写入",i)
}
party,_:=os.OpenFile("party.csv",os.O_WRONLY|os.O_CREATE, os.ModePerm)
defer party.Close()
wa:=csv.NewWriter(party)
urla:="http://www.xusong.com/api/NEWS/getPartyList.json?page=1&pageSize=10"
jsona,_:=http.Get(urla)
bodya,e:=ioutil.ReadAll(jsona.Body)
resa,_:=simplejson.NewJson([]byte(bodya))
for i:=0;i<10;i++{
cur:= resa.Get("result").Get("activityInfo").GetIndex(i)
addTime,_:= cur.Get("startTime").String()
content,_:=cur.Get("content").String()
title,_:=cur.Get("title").String()
id,_:=cur.Get("id").String()
url:= "http://www.xusong.com/event/"+id
wa.Write([]string{title,content,url,addTime})
fmt.Println("写入",i)
}
}
golang爬取VAE+的新闻动态
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...