go语言抓取twitter

来源:互联网 发布:白银交易软件下载 编辑:程序博客网 时间:2024/05/16 00:56

1. 第一步修改anaconda库, 以获取Search_meta_data ;

2. 调用anaconda, 抓取search数据,略


package anacondaimport ("net/url")type Search_meta_data struct {Completed_in float32 `json:"completed_in"`Max_id int64         `json:"max_id"`Max_id_str string    `json:"max_id_str"`Next_results string  `json:"next_results"`Query string         `json:"query"`Refresh_url string   `json:"refresh_url"`Count int     `json:"count"`Since_id     int     `json:"since_id"`Since_id_str string  `json:"since_id_str"`}type searchResponse struct {Statuses []TweetSearch_metadata Search_meta_data}func (a TwitterApi) GetSearch(queryString string, v url.Values) (data Search_meta_data, timeline []Tweet, err error) {var sr searchResponsev = cleanValues(v)v.Set("q", queryString)response_ch := make(chan response)a.queryQueue <- query{BaseUrl + "/search/tweets.json", v, &sr, _GET, response_ch}// We have to read from the response channel before assigning to timeline// Otherwise this will happen before the responses have been writtenresp := <-response_cherr = resp.errtimeline = sr.Statusesdata= sr.Search_metadatareturn data, timeline, err}



0 0