在窗口项目中导入了一个名为HtmlAgilityPack的开源类库(用来提取HTML内容),链接:http://htmlagilitypack.codeplex.com/
代码如下:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;using HtmlAgilityPack;//引入外部类库
using System.Net;
using System.IO;
using System.Xml.XPath;
using System.Xml;
namespace wangYeCaiJiExp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            //第一部分,获取完整的网页
            string urlToCrawl = textBox_url.Text;
            //generate http request
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(urlToCrawl);
            //use GET method to get url's html
            req.Method = "GET";
            //use request to get response
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            string htmlCharset = "utf-8";
            //use songtaste's html's charset GB2312 to decode html
            //otherwise will return messy code
            Encoding htmlEncoding = Encoding.GetEncoding(htmlCharset);
            StreamReader sr = new StreamReader(resp.GetResponseStream(), htmlEncoding);
            //read out the returned html
            string respHtml = sr.ReadToEnd();
            textBox_result.Text = respHtml;            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            
        }
    }
}
这个库中会用到xpath
但是using了以后依然会报错:
错误 1 类型“System.Xml.XPath.IXPathNavigable”在未被引用的程序集中定义。必须添加对程序集“System.Xml.XPath, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”的引用。 D:\VS2010\张大伟的词典\wangYeCaiJiExp\Form1.cs 45 13 wangYeCaiJiExp问题出在最后一行,也就是对HtmlAgilityPack的使用上,最后一行注释掉以后错误会消失。HTMLHtmlAgilityPack