public static List <WeiBoContentItem> GetWeiBoTopicContentV2(string topicName, string targetName = "") { List <WeiBoContentItem> res = new List <WeiBoContentItem>(); HtmlWeb webClient = new HtmlWeb(); HtmlDocument doc = webClient.Load("https://s.weibo.com/weibo/" + topicName + "&Refer=weibo_weibo&xsort=time&realtimeweibo=1"); doc.DocumentNode.InnerHtml = JavaScriptAnalyzer.Decode(doc.DocumentNode.InnerHtml); HtmlNodeCollection ContentList = doc.DocumentNode.SelectNodes("//div[@class='content clearfix']"); //获取一个话题项 ContentList.ToList().ForEach(p => { var item = new WeiBoContentItem(); //获取时间 var timeItem = p.SelectNodes(".//a[@class='W_textb']"); item.Time = Convert.ToDateTime(timeItem.FirstOrDefault()?.InnerText); var nickName = p.SelectNodes(".//a[@class='W_texta W_fb']"); item.Author = nickName.FirstOrDefault()?.InnerText.Trim(); var content = p.SelectNodes(".//p[@class='comment_txt']"); item.ContentStr = content.FirstOrDefault()?.InnerText.Trim(); var pic = p.SelectNodes(".//img[@action-type='feed_list_media_img']"); item.Pic = "https:" + pic.FirstOrDefault()?.Attributes.FirstOrDefault(c => c.Name == "src")?.Value.Replace("thumbnail", "large"); res.Add(item); }); return(res.Where(p => p.Author.Trim().Contains(targetName)).OrderByDescending(p => p.Time).ToList()); }
public override void ProcessRequset(GroupMessageReceivedContext msg, AnalysisMsg nowModel) { if (Config.ConfigModel.IsFuncOpen("查日常")) { WeiBoContentItem item = new WeiBoContentItem(); if (nowModel.What == "查日常") { if (lastestItem != null) { item = lastestItem.Time.Date == DateTime.Now.Date ? lastestItem : WeiboTool.GetWeiboByUid("1761587065", "1076031761587065", "#剑网3江湖百晓生#").OrderByDescending(p => p.Time).FirstOrDefault(); //WeiboTool.GetWeiBoTopicContentV1("剑网3江湖百晓生", "剑网3官方微博").FirstOrDefault(); } else { item = WeiboTool.GetWeiboByUid("1761587065", "1076031761587065", "#剑网3江湖百晓生#").OrderByDescending(p => p.Time).FirstOrDefault();//WeiboTool.GetWeiBoTopicContentV1("剑网3江湖百晓生", "剑网3官方微博").OrderByDescending(p => p.Time).FirstOrDefault(); } if (item == null) { _mahuaApi.SendGroupMessage(msg.FromGroup, "[日常]QAQ查询失败,请联系管理员"); } else { if (nowModel.Who == "文") { _mahuaApi.SendGroupMessage(msg.FromGroup).Text("[日常]来自 " + item.Author + ":").Newline().Text(item.ContentStr).Newline().Text(@"本信息由新浪微博-剑网3江湖百晓生-超话提供").Done(); } else { _mahuaApi.SendGroupMessage(msg.FromGroup).Text(CQCode.SendLink("查日常-" + item.Time.ToShortDateString(), item.Pic, item.ContentStr.Replace("#剑网3江湖百晓生#", "").Trim(), item.Pic)).Done(); } } } } successor.ProcessRequset(msg, nowModel); }
/// <summary> /// 获取微博话题内容列表(使用微博话题api),此接口返回内容详细,非常好用 /// </summary> /// <param name="topicId">话题名</param> /// <param name="tragetName">指定发送者名称</param> /// <returns></returns> public static List <WeiBoContentItem> GetWeiBoTopicContentV1(string topicName, string targetName = "") { var encode = System.Web.HttpUtility.UrlEncode(topicName); var res = JavaScriptAnalyzer.Decode(ToolClass.GetAPI($"https://m.weibo.cn/api/container/getIndex?type=uid&value=1761587065")); var ret = Newtonsoft.Json.JsonConvert.DeserializeObject <WeiBoTopicRes>(res); var card_Groups = new List <WeiBoTopicRes.Card_Group>(); ret.data.cards.Where(p => p.card_group != null).Select(p => p).ToList().ForEach( c => { card_Groups.AddRange(c.card_group); }); List <WeiBoContentItem> theres = new List <WeiBoContentItem>(); card_Groups.ForEach(p => { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(p.mblog.text); WeiBoContentItem item = new WeiBoContentItem { Pic = p.mblog.original_pic, Author = p.mblog.user.screen_name, ContentStr = htmlDocument.DocumentNode?.InnerText }; if (p.mblog.created_at.Contains("分钟")) { var getNum = Convert.ToInt32(p.mblog.created_at.Replace("分钟前", "")); item.Time = DateTime.Now.AddMinutes(-getNum); } else if (p.mblog.created_at.Contains("小时")) { var getNum = Convert.ToInt32(p.mblog.created_at.Replace("小时前", "")); item.Time = DateTime.Now.AddHours(-getNum); } else if (p.mblog.created_at.Contains("昨天")) { var getNum = Convert.ToDateTime(p.mblog.created_at.Replace("昨天", "").Trim()); item.Time = getNum.AddDays(-1); } else if (p.mblog.created_at.Contains("前天")) { var getNum = Convert.ToDateTime(p.mblog.created_at.Replace("前天", "").Trim()); item.Time = getNum.AddDays(-2); } else { item.Time = Convert.ToDateTime(p.mblog.created_at); } theres.Add(item); }); return(theres.Where(p => p.Author.Trim().Contains(targetName)).OrderByDescending(p => p.Time).ToList()); }
public static List <WeiBoContentItem> GetWeiboByUid(string Uid, string ContainerId, string TopicFilter = "") { var res = /*JavaScriptAnalyzer.Decode(*/ ToolClass.GetAPI($"https://m.weibo.cn/api/container/getIndex?type=uid&value={Uid}&containerid={ContainerId}") /*)*/; var ret = Newtonsoft.Json.JsonConvert.DeserializeObject <WeiBoDirectContentItem.WeiBoDirectRes>(res); var card_Groups = ret.data.cards.ToList(); List <WeiBoContentItem> theres = new List <WeiBoContentItem>(); card_Groups.ForEach(p => { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(p.mblog.text); WeiBoContentItem item = new WeiBoContentItem { Pic = p.mblog.original_pic, Author = p.mblog.user.screen_name, ContentStr = htmlDocument.DocumentNode?.InnerText }; if (p.mblog.created_at.Contains("分钟")) { var getNum = Convert.ToInt32(p.mblog.created_at.Replace("分钟前", "")); item.Time = DateTime.Now.AddMinutes(-getNum); } else if (p.mblog.created_at.Contains("小时")) { var getNum = Convert.ToInt32(p.mblog.created_at.Replace("小时前", "")); item.Time = DateTime.Now.AddHours(-getNum); } else if (p.mblog.created_at.Contains("昨天")) { var getNum = Convert.ToDateTime(p.mblog.created_at.Replace("昨天", "").Trim()); item.Time = getNum.AddDays(-1); } else if (p.mblog.created_at.Contains("前天")) { var getNum = Convert.ToDateTime(p.mblog.created_at.Replace("前天", "").Trim()); item.Time = getNum.AddDays(-2); } else { item.Time = Convert.ToDateTime(p.mblog.created_at); } theres.Add(item); }); return(theres.Where(p => p.ContentStr.Contains(TopicFilter)).OrderByDescending(p => p.Time).ToList()); }
public override void ProcessRequset(GroupMessageReceivedContext msg, AnalysisMsg nowModel) { if (Config.ConfigModel.IsFuncOpen("查日常")) { WeiBoContentItem item = new WeiBoContentItem(); if (nowModel.What == "查日常") { if (lastestItem != null) { item = (lastestItem.Time.Date == DateTime.Now.Date) ? lastestItem : WeiboTool.GetWeiboByUid("1761587065", "1076031761587065", "#剑网3江湖百晓生#").OrderByDescending(p => p.Time).FirstOrDefault(); } else { item = WeiboTool.GetWeiboByUid("1761587065", "1076031761587065", "#剑网3江湖百晓生#").OrderByDescending(p => p.Time).FirstOrDefault(); } lastestItem = item; if (nowModel.OriginStr.Contains("文") && item != null) { _mahuaApi.SendGroupMessage(msg.FromGroup).Text("[日常]来自 " + item.Author + ":").Newline().Text(item.ContentStr).Newline().Text($"图片-{item.Pic}").Newline().Text(@"本信息由新浪微博-剑网3江湖百晓生-超话提供").Done(); } else if (item != null) { _mahuaApi.SendGroupMessage(msg.FromGroup).Text(CQCode.SendLink("查日常-" + item.Time.ToShortDateString(), item.Pic, item.ContentStr.Replace("#剑网3江湖百晓生#", "").Trim(), item.Pic)).Done(); } if (item == null) { if (Config.DefaltItem != null) { _mahuaApi.SendGroupMessage(msg.FromGroup).Text("[日常]QAQ官微又偷懒了,为您提供" + Config.DefaltItem.Time.ToShortDateString() + " 来自 " + Config.DefaltItem.Author + ":").Newline().Text(Config.DefaltItem.ContentStr).Newline().Text(@"本信息由官博偷懒没发日常倾情触发,更新请通过建议提交日常信息给我~").Done(); } else { _mahuaApi.SendGroupMessage(msg.FromGroup, "[日常]QAQ查询失败,请联系管理员"); } } } } successor.ProcessRequset(msg, nowModel); }