请帮助我从网站中提取一些信息. [英] Please help me to extract some information from website.

查看:102
本文介绍了请帮助我从网站中提取一些信息.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我整天都在尝试熟悉HTML Agility Pack.
我只是在学习C#.
网站是www.tikr.ru
我需要主要报价-今天是1519.95.
我什至得到了XPath表达式,它是使用FireBug for Firefox的//* [@@ =="csPrice"].
我不明白这段代码有什么问题.


All day long i was trying to get familiar with HTML Agility Pack.
I am just learning C#.
Website is www.tikr.ru
I need main quote - which is 1519.95 for today.
I even got XPath expression for it, which is //*[@id="csPrice"] using FireBug for Firefox.
I can''t understand what''s wrong with this code.


static void Main(string[] args)
{
    var webGet = new HtmlWeb();
    var document = webGet.Load("http://www.tikr.ru");
    var prices = from lnks in document.DocumentNode.Descendants()
          where lnks.Name == "//*[@id='csPrice']"
          select new { Price = lnks.Attributes["csPrice"].Value};

    foreach(var item in prices)
    {
        string message = "The Price is: " + item.Price.ToString();
        Console.WriteLine(message);
        Console.ReadLine();
    }
}

推荐答案

这将完成您的工作
This will do your work
void GetQuote()
{
            WebClient wb = new WebClient();
            string htmldoc= wb.DownloadString("http://www.tikr.ru/");
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(htmldoc);
            HtmlAgilityPack.HtmlNode node = doc.DocumentNode.SelectSingleNode("//span[@id=\"csPrice\"]");
            string quote = node.InnerText;
}



这里的``quote''直接显示今天的报价,即1519.95.

:)



Here the ''quote'' directly displays the today''s quote i.e 1519.95 .

:)


非常感谢.这是非常有用的回复!!!我认为这也将对其他用户有所帮助.
Thank you very much. This is very useful reply!!! I think it will be helpful for other users also.


这篇关于请帮助我从网站中提取一些信息.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆