是不是有人相抓取网页上面的内容,放到别的网站上面。下面我给大家介绍一种最常用的方法:
用HtmlAgilityPack 组件。
public String GetHtml() { string url = "http://t.news.fx168.com/"; HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { using (Stream stream = response.GetResponseStream()) { HtmlDocument doc = new HtmlDocument(); doc.Load(stream, System.Text.Encoding.UTF8); HtmlNode node = doc.DocumentNode.SelectSingleNode("//div[@class=‘hzh_FX168_news_main_left_listbg3‘]"); return node.InnerHtml; } } }
大家可以运行下试试,抓取了火线速递的内容页面新闻列表。抓取规则是抓取DIV的CLASS为hzh_FX168_news_main_left_listbg3内的内容。