Golang Crawling holiday information

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

When you visit a blog, you find someone raises a question, how to judge whether it is a holiday. Think for a while and think of two solutions

1. Keep track of your holiday information 2. Third-party Data interface

I recorded this directly by my pass off, cumbersome and may be lost and the like. Then the third-party data interface is the solution.

Through Baidu found a look good

https://www.juhe.cn/docs/api/id/177/aid/601

Request Parameter Description:

name required type description
Key Is String Appkey you are applying for
Year Is String Specify the year in YYYY format, for example: 2015

Return parameter Description:

name type description
Error_code Int Return Status Code
Reason String return reason
Result String Return entity Content
Holidaylist String Current year holiday list
Year String Year

Free 100 times, overall very good. After reviewing his parameters, I began to write the code formally.

First, I'm using the Beego HTTP library.

package mainimport ("github.com/astaxie/beego/httplib""strconv""log")var (//个人appKeyAppKey = "")func main() {//从1970年到2070年for i := 0; i <= 100; i++ {year := strconv.Itoa(1970 + i) //年份request := httplib.Get("http://v.juhe.cn/calendar/year?year=" + year + "&key=" + AppKey)//保存为文件if err := request.ToFile("data/" + year + ".json"); err != nil {log.Println(err.Error())}log.Println(year + " 成功")}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.