public static void GetAllItems(string url, string cookie) { string host = new Uri(url).Host; do { string html = WebOperating.GetMode(url, host, cookie, host); var doc = new HtmlDocument(); doc.LoadHtml(html); var root = doc.DocumentNode; var torrentnodes = root.SelectNodes("//table[@class='torrentname']"); foreach (var torrent in torrentnodes) { if (!IsRunning) { break; } var torrentUrl = torrent.SelectSingleNode(torrent.XPath + "/tr/td[1]/a").GetAttributeValue("href", ""); torrentUrl = HttpUtility.HtmlDecode(torrentUrl); WriteLog("开始处理:" + torrentUrl); Console.WriteLine(torrentUrl); GetDetail(new Uri(new Uri(url), torrentUrl).ToString(), cookie); Thread.Sleep(10000); } var nextPage = root.SelectSingleNode("//b[@title='Alt+Pagedown']"); if (nextPage != null) { var href = nextPage.ParentNode.GetAttributeValue("href", ""); if (href != "") { href = HttpUtility.HtmlDecode(href); url = new Uri(new Uri(url), href).ToString(); } else { url = string.Empty; } } else { url = string.Empty; } Console.WriteLine(url); WriteLog("翻到下一页:" + url); } while (IsRunning && url != string.Empty); }
public static void GetDetail(string url, string cookie) { string host = new Uri(url).Host; string html = WebOperating.GetMode(url, host, cookie, host); var doc = new HtmlDocument(); doc.LoadHtml(html); var root = doc.DocumentNode; var thanksButton = root.SelectSingleNode("//input[@id='saythanks']"); if (thanksButton.GetAttributeValue("disabled", "") != "") { Console.WriteLine("已经说过谢谢"); WriteLog("已经说过谢谢:" + url); } else { Console.WriteLine("没有说过谢谢"); SayThanks(url, cookie); } }