private IList <Comment> GetComments(string requestUrl) { IList <Comment> comments = new List <Comment>(); string html = ArticleParserHelper.GetHtmlStr(requestUrl); try { string result = Regex.Unescape(html); //Translate unicode to Chinese characters string jsonResult = CleanJsonString(result); JObject obj = JObject.Parse(jsonResult); IList <JToken> jsonComments = obj["data"]["commentid"].Children().ToList(); foreach (JToken token in jsonComments) { NewsComment_QQ cmt = JsonConvert.DeserializeObject <NewsComment_QQ>(token.ToString()); comments.Add(new Comment() { Cotent = cmt.Content, Vote = Int32.Parse(cmt.Up) }); } } catch (Exception) { return(comments); } return(comments); }
public List <JToken> GetJsonNewsList() { string max_behot_time = string.Empty; string uri = string.Empty; string jsonResult = string.Empty; int onceGet = InitInfo.ToutiaoOnceGetMaxCount; List <JToken> jsonNewsList = new List <JToken>(); for (int i = 0; i < webSetting.CrawNewsCount / onceGet; i++) { uri = string.Format(SiteNewsUrl, max_behot_time, onceGet); jsonResult = ArticleParserHelper.GetHtmlStr(uri); JObject obj = JObject.Parse(jsonResult); jsonNewsList.AddRange(obj["data"].Children().ToList()); max_behot_time = obj["next"]["max_behot_time"].ToString(); } if (webSetting.CrawNewsCount % onceGet > 0) { uri = string.Format(SiteNewsUrl, max_behot_time, webSetting.CrawNewsCount % onceGet); jsonResult = ArticleParserHelper.GetHtmlStr(uri); JObject obj = JObject.Parse(jsonResult); jsonNewsList.AddRange(obj["data"].Children().ToList()); } return(jsonNewsList); }