沙场点兵高清下载,厦门双十中学校花,英语手抄小报
htmlagilitypack是一个开源的解析html元素的类库,最大的特点是可以通过xpath来解析hmtl,如果您以前用c#操作过xml,那么使用起htmlagilitypack也会得心应手。目前版本更新的是非常的快,最新更新时间还是19年的呢!
xpath即为xml路径语言,它是一种用来确定xml(标准通用标记语言的子集)文档中某部分位置的语言。xpath基于xml的树状结构,提供在数据结构树中找寻节点的能力。起初 xpath 的提出的初衷是将其作为一个通用的、介于xpointer与xsl间的语法模型。但是 xpath 很快的被开发者采用来当作小型查询语言。
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using htmlagilitypack; using system.io; using system.net; namespace datagridviewdemo { public class httphelper { static readonly string urltemplate = "http://yun.java1234.com/search?page={0}&q={1}"; public static list<bdwpresource> request(string key, string start) { string url = string.format(urltemplate, key, start); httpwebrequest httprequest = (httpwebrequest)webrequest.create(url); httprequest.accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"; httprequest.useragent = "mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/69.0.3497.100 safari/537.36"; try { htmlweb webclient = new htmlweb(); htmldocument doc = webclient.load(url); if (doc != null) { //加载文档对象 { var content = doc.documentnode.selectsinglenode("/html/body/div[2]/div[3]/div/div/div[2]/ul"); if (content != null) { list<bdwpresource> list = new list<bdwpresource>(); var targetli = content.selectnodes(@"li"); foreach (var item in targetli) { list.add(new bdwpresource() { title = item.selectsinglenode("span[1]/a").innertext, unescapedurl = "http://yun.java1234.com/" + item.selectsinglenode("span[1]/a").attributes["href"].value.trim(), content = item.selectsinglenode("span[2]").innertext.trim() }); } return list; } } return null; } else { return null; } } catch { return null; } } } }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论