golang爬取VAE+的新闻动态

栏目: Go · 发布时间: 7年前

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+的新闻动态》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

算法笔记上机训练实战指南

算法笔记上机训练实战指南

胡凡、曾磊 / 机械工业出版社 / 2016-7 / 57

《算法笔记上机训练实战指南》是《算法笔记》的配套习题集,内容按照《算法笔记》的章节顺序进行编排,其中整理归类了PAT甲级、乙级共150多道题的详细题解,大部分题解均编有题意、样例解释、思路、注意点、参考代码,且代码中包含了详细的注释。读者可以通过本书对《算法笔记》的知识点进行更深入的学习和理解。书中印有大量二维码,用以实时更新或补充书籍的内容及发布本书的勘误。 《算法笔记上机训练实战指南》可......一起来看看 《算法笔记上机训练实战指南》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

MD5 加密
MD5 加密

MD5 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具