• 女朋友经常问影视剧, 答不上来怎么办?


    女朋友经常问影视剧, 答不上来怎么办?朋友介绍了一个好站(www.5ddy.net),   全是豆瓣高分影视。 非常666.   今日特写一个查询小工具, 根据名称快速得到它的剧集。 

    设计思路

    1.  获取它接口的JSON数据。 

    2.  解析JSON, 获取电影名和链接。 

    3.  发给女朋友。 

    核心代码。 

     1         /// <summary>
     2         /// 获取HTML源文件
     3         /// </summary>
     4         /// <param name="url"></param>
     5         /// <returns></returns>
     6         public static string HttpClientGetHtmls(string url)
     7         {
     8             try
     9             {
    10                 if (url == null || url.Length == 0)
    11                 {
    12                     return null;
    13                 }
    14                 string result = null;
    15                 HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.Create(url);
    16                 wbRequest.Method = "GET";
    17                 wbRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
    18                 wbRequest.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";//模拟user
    19                 wbRequest.Timeout = 3000;//设计超时时间
    20                 try
    21                 {
    22                     HttpWebResponse wbResponse = (HttpWebResponse)wbRequest.GetResponse();
    23                     using (Stream responseStream = wbResponse.GetResponseStream())
    24                     {
    25                         using (StreamReader sReader = new StreamReader(responseStream))
    26                         {
    27                             result = sReader.ReadToEnd();
    28                         }
    29                     }
    30                 }
    31                 catch (Exception e)
    32                 {
    33                     Console.WriteLine(e.StackTrace);
    34                 }
    35 
    36                 return result;
    37             }
    38             catch (Exception exception)
    39             {
    40             }
    41             return "";
    42         }

    解析JSON格式。 

     1         public string searchvod(string msg)
     2         {
     3             StringBuilder result = new StringBuilder();
     4             msg = msg.Replace("", "");
     5             msg = Regex.Replace(msg, "[ \[ \] \^ \-_*×――(^)(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;"‘’“”-]", "");
     6             string html = HttpClientGetHtmls("http://www.5ddy.net/api.php/provide/vod/?ac=list&wd=" + msg);
     7             JObject model = JObject.Parse(html); //解析json
     8             if (model != null)
     9                 foreach (var item in model["list"])
    10                 {
    11                     var id = item["vod_id"];
    12                     var dyname = item["vod_name"];
    13                     string url = "https://www.5ddy.net/voddetail/" + id + ".html";
    14                     var s = SinaShortUrl(url);
    15                     result.Append(dyname + ":" + s + "
    ");
    16                 }
    17             return result.ToString();
    18         }

    只要传电影或电视剧名称, 就能快速找到它的链接了。 配合自己写的桌面工具, 爽得不要不要的。 

  • 相关阅读:
    萌新入坑 实验六 团队作业2:开心农场信息系统
    萌新入坑 实验六团队作业2:开心农场信息系统
    萌新入坑 实验五 团队作业1:软件研发团队组建与软件案例分析
    实验八 团队作业4:团队项目需求建模与系统设计
    狗蛋带仨妞 实验七 团队作业3:团队项目需求分析与原型设计
    狗蛋带仨妞 实验六 团队作业2:开心农场信息系统
    狗蛋带仨妞 实验五 团队作业1:软件研发团队组建与软件案例分析
    nginx 配置参数详细说明
    mac清除launchpad 应用程序和图标
    CentOS 7.5在线安装Docker 18.09.3
  • 原文地址:https://www.cnblogs.com/jackrebel/p/11613349.html
Copyright © 2020-2023  润新知