时间:2021-03-29 09:42:04 | 栏目:.NET代码 | 点击:次
1.添加引用.net 引用Microsoft.mshtml
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string str = wc.DownloadString(@"https://www.jb51.net/web/73969.html");
HTMLDocumentClass doc = new HTMLDocumentClass();//获取html对象
doc.designMode = "on"; //不让解析引擎去尝试运行javascript
doc.IHTMLDocument2_write(str);把html 文档写入html对象中
doc.close();关闭写流
Console.WriteLine(doc.title);输出标题
Console.WriteLine(doc.body.innerText); 输出body
Console.ReadKey();