参见英文答案 >
What is the best way to parse html in C#? [closed]15个
有解决HTML代码的方法吗?
有解决HTML代码的方法吗?
即GetElementByTagName(“abc”).GetElementByTagName(“tag”)
我有这个代码块…
private void LoadProfilePage() { string sURL; sURL = "http://www.abcd1234.com/abcd1234"; WebRequest wrGETURL; wrGETURL = WebRequest.Create(sURL); //WebProxy myProxy = new WebProxy("myproxy",80); //myProxy.BypassProxyOnLocal = true; //wrGETURL.Proxy = WebProxy.GetDefaultProxy(); Stream objStream; objStream = wrGETURL.GetResponse().GetResponseStream(); if (objStream != null) { StreamReader objReader = new StreamReader(objStream); string sLine = objReader.ReadToEnd(); if (String.IsNullOrEmpty(sLine) == false) { .... } } }
解决方法
你可以使用优秀的
HTML Agility Pack.
This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don’t HAVE to understand XPATH nor XSLT to use it,don’t worry…). It is a .NET code library that allows you to parse “out of the web” HTML files. The parser is very tolerant with “real world” malformed HTML. The object model is very similar to what proposes System.Xml,but for HTML documents (or streams).
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。