在c#中从网页获取动态信息?

在c#中从网页获取动态信息?,c#,C#,我有一个网页上的动态信息,我想得到它作为一个字符串 网站: 还有“今天”xx.xx%和价格信息也会发生变化。我在页面的源代码中找到了它,我知道我可以得到源代码页面,然后开始删除部分内容,但我认为这不是最有效的方法 这是我的尝试,但我认为这是一种失败 string pricePLine; string[] finditems = new string[] { @"<td class=""rise"">", @"<span id=""exactPrice"" class=""rig

我有一个网页上的动态信息,我想得到它作为一个字符串

网站:

还有“今天”xx.xx%和价格信息也会发生变化。我在页面的源代码中找到了它,我知道我可以得到源代码页面,然后开始删除部分内容,但我认为这不是最有效的方法

这是我的尝试,但我认为这是一种失败

string pricePLine;
string[] finditems = new string[] { @"<td class=""rise"">", @"<span id=""exactPrice"" class=""right"">" }; // the part in the HTML file that dosen't change 

private void button1_Click(object sender, EventArgs e)
{
    WebClient web = new WebClient();
    string URL = textBox1.Text;
    string[] result = web.DownloadString(URL).Split('\n');

    collectData(result, finditems[0]);

    textBox1.Clear();
    textBox1.Focus();
}

private void collectData(string[] data, string shitToFind)
{
    foreach (string item in data)
    {
        if (item.Contains(shitToFind))
        {

        }
    }
}
字符串价格线;
字符串[]finditems=新字符串[]{@“@”};//HTML文件中不变的部分
私有无效按钮1\u单击(对象发送者,事件参数e)
{
WebClient web=新的WebClient();
字符串URL=textBox1.Text;
string[]result=web.DownloadString(URL).Split('\n');
收集数据(结果,finditems[0]);
textBox1.Clear();
textBox1.Focus();
}
私有void collectData(字符串[]数据,字符串shitToFind)
{
foreach(数据中的字符串项)
{
if(项目包含(shitToFind))
{
}
}
}

解析html页面时,请使用真正的html解析器,如


您的问题是什么?您的代码以什么方式失败?
var html = new WebClient().DownloadString("http://geupdater.com/items/377-raw-lobster");
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
var node = doc.DocumentNode.SelectNodes("//article[@class='last half item']");
var values = node.Descendants("th")
                .Zip(node.Descendants("td"), (x, y) => new { Name = x.InnerText, Value = y.InnerText })
                .ToDictionary(x => x.Name, x => x.Value);