吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2089|回复: 20
收起左侧

[C&C++ 原创] 头条、知乎热搜排行榜

[复制链接]
ylqxid 发表于 2023-6-25 10:44
[C#] 纯文本查看 复制代码
using QQ;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Data;

namespace HotSearch
{
    enum Type
    {
        Zhihu,
        Toutiao
    };

    struct Con
    {
        public string title;
        public string hotValue;
        public string url;
    }

    class GetData
    {
        private string ZhihuAPI = @"https://api.codelife.cc/api/top/list?lang=cn&id=mproPpoq6O&size=50";
        private string ToutiaoAPI = @"https://api.codelife.cc/api/top/list?lang=cn&id=toutiao&size=50";

        private Dictionary<Type, string> typeApiDic = new Dictionary<Type, string>();

        public GetData()
        {
            typeApiDic.Add(Type.Toutiao, this.ToutiaoAPI);
            typeApiDic.Add(Type.Zhihu, this.ZhihuAPI);
        }


        public string conHtml(Type type, string title = "")
        {
            List<Con> conList = this.Get(type);
            string conStr = this.conHtml(conList, title);
            return conStr;
        }


        private List<Con> Get(Type type)
        {
            List<Con> res = new List<Con>();
            string url = typeApiDic[type];

            string conStr = "";
            bool isReturn = webRequest.Get(url, "", out conStr);
            if (!string.IsNullOrWhiteSpace(conStr))
            {
                JObject jsonData = JObject.Parse(conStr);
                JArray jsonDataArray = (JArray)jsonData["data"];
                foreach (var item in jsonDataArray)
                {
                    Con conItem = new Con();
                    conItem.title = (string)item["title"];
                    string hot = (string)item["hotValue"];
                    conItem.hotValue = string.IsNullOrWhiteSpace(hot) ? "" : hot.Replace("热度", "");
                    string link = (string)item["link"];
                    if (!string.IsNullOrWhiteSpace(link))
                    {
                        conItem.url = System.Web.HttpUtility.UrlDecode(link, Encoding.UTF8); //Encoding.GetEncoding("GB2312")
                    }
                    res.Add(conItem);
                }
            }
            else
            {
                Log.writeLog(string.Format("url{0} 返回值为空", url), true);
            }
            return res;
        }


        private string conHtml(List<Con> conList, string title = "")
        {
            StringBuilder sb = new StringBuilder();
            if (!string.IsNullOrWhiteSpace(title))
            {
                sb.Append("<font color = 'Red' ><b> " + title + "</font>");
                sb.Append("<br>");
                sb.Append("<hr>");
            }

            sb.Append(string.Format("<html><head><meta name='viewport' content='width=device-width,initial-scale=0.8' ><title>Reports{0}</title></head><body><table border= 3><thead>", "详情"));
            sb.Append("<th bgcolor='66CCFF'>序号</th><th>标题</th><th>热度</th><th>链接</th>");
            sb.Append("</thead>");

            for (int i = 0; i < conList.Count(); i++)
            {
                sb.Append("<tr>");
                sb.Append(string.Format("<td bgcolor='66CCFF'>{0}</td>", i + 1));
                sb.Append(string.Format("<td> {0}</td>", conList[i].title));
                sb.Append(string.Format("<td> {0}</td>", conList[i].hotValue));
                sb.Append(string.Format("<td> <a href = '{0}' target = '_blank' >链接 </a></td>", conList[i].url));
                sb.Append("</tr>");
            }

            sb.Append("</table>");
            sb.Append("<tbody></body>");
            return sb.ToString();
        }

    }
}

如上代码是爬虫数据代码。数据推送服务代码,暂不贴示。
获取得到数据数据,再借助微信推送消息平台Wxpusher,即可推送信息至微信。并附有数据链接

wzd.jpg

免费评分

参与人数 4吾爱币 +4 热心值 +4 收起 理由
why3316 + 1 + 1 谢谢@Thanks!
jsboy + 1 + 1 我很赞同!
己中求 + 1 + 1 热心回复!
YY0716 + 1 + 1 热心回复!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

microgly 发表于 2023-7-4 10:46
这个api的热榜内容不是实时的,不知道更新频率是多长时间
 楼主| ylqxid 发表于 2023-7-3 16:14
kiddhuang 发表于 2023-7-1 21:40
楼主,请问这个有没有做好的软件啊。

微信公众号
使用微信公众号。作为接受信息载体。
我的后台服务将数据推送给微信公众号,只需要客户关注微信公众号即可。
kiddhuang 发表于 2023-7-1 21:40
ebuy177 发表于 2023-7-3 19:22
不错,能不能推到我的公众号?
 楼主| ylqxid 发表于 2023-7-4 09:44
ebuy177 发表于 2023-7-3 19:22
不错,能不能推到我的公众号?

应该是可以的。
 楼主| ylqxid 发表于 2023-7-4 14:54
microgly 发表于 2023-7-4 10:46
这个api的热榜内容不是实时的,不知道更新频率是多长时间

是的呢,大概是4个小时更新一次吧
liangce_media 发表于 2023-7-19 08:02
这个有做好的软件吗
 楼主| ylqxid 发表于 2023-7-19 17:19
liangce_media 发表于 2023-7-19 08:02
这个有做好的软件吗

我做了微信公众号,作为接受信息载体。做好的软件,还需要运行,比较麻烦。
没有微信公众号,好用。
pgdhao123 发表于 2023-8-4 14:01
楼主,你的公众号在哪里呢?没看到,怎么对接呢
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-3 22:55

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表