最近在做一個聚合搜索引擎,根據電影名,得到資源鏈接, 並且必須和自己的QQ電影資源機器人兼容, 根據電影名自動回復電影鏈接。
資源網站:http://www.wxtv.net/api.php/provide/vod/?ac=list&wd=電影關鍵詞, 可根據該站提供的API接口, 得到json數據。
比如, https://www.wxtv.net/api.php/provide/vod/?ac=list&wd=鬼吹燈, 可以得到json格式, vod_id是電影ID, vod_name:電影名稱,vod_time:更新時間。
拿到json數據后, 可通過Jobject解析這個json, 拼接出該站的具體url。
核心代碼如下:
1 StringBuilder result = new StringBuilder(); 2 msg = ReplaceTitle(msg); 3 msg = Regex.Replace(msg, "[ \\[ \\] \\^ \\-_*×――(^)(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", ""); 4 string html = HttpClientGetHtmls("https://www.wxtv.net/api.php/provide/vod/?ac=list&wd=" + msg); 5 JObject model = JObject.Parse(html); //解析json 6 if (model != null) 7 foreach (var item in model["list"]) 8 { 9 var id = item["vod_id"]; 10 var dyname = item["vod_name"]; 11 string url = "https://www.wxtv.net/voddetail/" + id + ".html?formQQ=" + formqq; 12 var s = SinaShortUrl(url); 13 result.Append(dyname + ":" + s + "\r\n"); 14 } 15 return result.ToString();