예제 #1
0
        /// <summary>
        /// 获取头条的原始文章
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string GetTouTiaoArticle(string url)
        {
            var headers = new Dictionary <string, string>();

            headers.Add("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
            headers.Add("accept-encoding", "gzip, deflate, br");
            headers.Add("accept-language", "zh-CN,zh;q=0.9,en;q=0.8");
            headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36");

            var res = HTTP.Get(url, headers);

            return(res);
        }
예제 #2
0
 /// <summary>
 /// 从url中保存一个原始文章
 /// </summary>
 /// <param name="url"></param>
 /// <param name="headers"></param>
 /// <returns></returns>
 public RES SaveArticleFromUrl(string url, string headers)
 {
     try
     {
         var content = HTTP.Get(url, string.IsNullOrWhiteSpace(headers) ? null: JSON.ToObject <Dictionary <string, string> >(headers));
         var inst    = new YunArticle();
         inst.ID         = Guid.NewGuid();
         inst.Status     = (int)ENUM.实体状态.可用;
         inst.Title      = null;
         inst.Url        = url;
         inst.Content    = content;
         inst.CreateTime = DateTime.Now;
         inst.UpdateTime = DateTime.Now;
         var db = ModelEF.GetInst();
         db.YunArticles.Add(inst);
         db.SaveChangesAsync();
         return(RES.OK(inst));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex.Message));
     }
 }