/// <summary> /// 传入整个页面的html,返回只有任务列表那部分html /// 即<ul></ul>之间的html /// 并把所有点击的链接都去除 /// </summary> /// <param name="html"></param> /// <returns></returns> public static string getToDoTaskHtmlUl(string html) { NSoup.Nodes.Document doc = NSoup.NSoupClient.Parse(html); NSoup.Select.Elements ele = doc.GetElementsByClass("con_left"); if (ele.IsEmpty) { NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); logger.Error("无法解析html:items_ul"); return(null); } ele[0].GetElementsByTag("a").RemoveAttr("href");//把所有点击的链接都去除 StringBuilder sb = new StringBuilder("<div class=\"con_left\">"); sb.Append(ele[0].Html()); sb.Append("</div>"); string ulHtml = sb.ToString(); return(ulHtml); }
public string Search(string search) { string url = "https://search.mcmod.cn/s?key=" + search.Split('(')[0] + "&site=&filter=1&mold=0"; try { NSoup.Nodes.Document doc = NSoup.NSoupClient.Parse(web.getHtml(url)); var List = doc.GetElementsByClass("search-result-list"); var item = NSoup.NSoupClient.Parse(List.ToString()).GetElementsByClass("result-item"); foreach (var i in item) { var j = NSoup.NSoupClient.Parse(i.GetElementsByClass("head").ToString()); var a = j.GetElementsByTag("a"); var title = a.Text.Replace("<em>", "").Replace("</em>", "").Replace("\"", "").Replace(" ", ""); if (title.IndexOf(search.Split('(')[0].Replace(" ", "")) > 0) { return(a[1].Attr("href").ToString()); } } } catch (Exception ex) { } return(null); }