public static void AddNews(NewsInfoForJson news) { try { string timeAuth = DateTime.Now.Millisecond.ToString(); string cryptStr = Encryption.Encrypt("addnews" + timeAuth); news.befrom = HttpUtility.UrlEncode(news.befrom); news.Filename = HttpUtility.UrlEncode(news.Filename); news.newstext = HttpUtility.UrlEncode(HttpUtility.HtmlEncode(news.newstext)); news.Title = HttpUtility.UrlEncode(HttpUtility.HtmlEncode(news.Title)); news.Titlepic = HttpUtility.UrlEncode(news.Titlepic); string dataStr = string.Format("action=addnews&titlepic={0}&title={1}&newsform={2}&newstime={3}&onclick={4}&classname={5}&filename={6}&classid={7}&ishearder={8}&newstext={9}&befrom={10}&isbottom={11}&rd={12}&auth={13}", news.Titlepic, news.Title, news.NewsForm, news.NewsTime, news.Onclick, news.ClassName, news.Filename, news.Classid, news.IsHearder, news.newstext, news.befrom, news.isbottom, timeAuth, cryptStr); //string result = HttpHelper.HTTP_POST("http://localhost:21422/RecommendGames.aspx", dataStr); string result = HttpHelper.HTTP_POST("http://recommendgames2.pettostudio.net/RecommendGames.aspx", dataStr); if (result.ToLower() != "200:ok") { throw new Exception(result); } } catch (Exception) { throw; } }
public static List<NewsInfoForJson> GetNewsInfoList(string url) { HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb(); HtmlAgilityPack.HtmlDocument doc = web.Load(url); HtmlAgilityPack.HtmlNodeCollection clooection = doc.DocumentNode.SelectNodes("//div[@class=\"grid_item visor-article-teaser list_default\"]"); List<NewsInfoForJson> result = new List<NewsInfoForJson>(); if (clooection != null && clooection.Count > 0) { foreach (var c in clooection) { NewsInfoForJson news_t = new NewsInfoForJson(); HtmlAgilityPack.HtmlNode imageNode = c.SelectSingleNode(".//img"); if (imageNode != null) { string image_t = imageNode.GetAttributeValue("src", ""); news_t.Titlepic = image_t.StartsWith("http") ? image_t : HOST + image_t.TrimStart('/'); } HtmlAgilityPack.HtmlNode urlNode = c.SelectSingleNode(".//a[@class='grid_img']"); if (urlNode != null) { string url_t = urlNode.GetAttributeValue("href", ""); news_t.befrom = url_t.StartsWith("http") ? url_t : HOST + url_t.TrimStart('/'); } HtmlAgilityPack.HtmlNode timeNode = c.SelectSingleNode(".//span[@class='grid_time']"); if (timeNode != null) { news_t.NewsTime = timeNode.InnerText; } HtmlAgilityPack.HtmlNode titleNode = c.SelectSingleNode(".//*[@class='grid_title']"); if (titleNode != null) { news_t.Title = HttpUtility.HtmlDecode(titleNode.InnerText); } news_t.NewsForm = "news"; GetContentText(news_t.befrom, ref news_t); news_t.Onclick = new Random().Next(100, 2000).ToString(); result.Add(news_t); } } return result; }
public static void GetContentText(string url, ref NewsInfoForJson newsModel_t) { HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb(); HtmlAgilityPack.HtmlDocument doc = web.Load(url); HtmlAgilityPack.HtmlNode contentNode = doc.DocumentNode.SelectSingleNode("//div[@class=\"field field-name-body field-type-text-with-summary field-label-hidden\"]/div[@class=\"field-items\"]/div[@class=\"field-item even\"]"); if (contentNode != null) { newsModel_t.newstext = contentNode.OuterHtml; } HtmlAgilityPack.HtmlNode articleTimeNode = doc.DocumentNode.SelectSingleNode("//time[@class=\"article-time\"]"); if (contentNode != null) { newsModel_t.NewsTime = articleTimeNode.InnerText.Replace(" at ", " ").Replace(" EDT",""); newsModel_t.NewsTime = DateTime.Parse(newsModel_t.NewsTime).ToString("yyyy-MM-dd HH:mm:ss"); } HtmlAgilityPack.HtmlNodeCollection nodeCollection = doc.DocumentNode.SelectNodes("//a[@class=\"cta large\"]"); if (nodeCollection != null && nodeCollection.Count > 0) { foreach (var node in nodeCollection) { string url_t = HttpUtility.HtmlDecode(HttpUtility.UrlDecode(node.GetAttributeValue("href", ""))); if (url_t.Contains("www.microsoft.com") && url_t.Contains("store") && url_t.Contains("apps")) { int index_0 = url_t.IndexOf("&url=https") + 5; int index_1 = url_t.LastIndexOf("&token="); string fileName_t = HttpUtility.UrlDecode( index_1 > 0 ? url_t.Substring(index_0, index_1 - index_0) : url_t.Substring(index_0)); int index_2 = fileName_t.LastIndexOf("&ourl=http"); if (index_2 > 0) { newsModel_t.Filename = fileName_t.Substring(0, index_2); } else { newsModel_t.Filename = fileName_t; } newsModel_t.NewsForm = "pingce"; Console.WriteLine("url:" + newsModel_t.Filename); } } } }