在Windows手机中进行搜索查询并在结果框中填充结果

时间:2012-11-25 19:42:19

标签: windows-phone-7 xml-parsing html-parsing html-agility-pack

我是Windows Phone编程的新手,我试图为例如搜索查询 http://www.flipkart.com/search/a/computers?query=ipad+3

我在webclient的帮助下使用downloadStringAsync函数执行此操作。现在要从我的所有搜索中检索结果,我发现它必须是一个XML文档,但是如何知道它的后代,子项,属性等,我无法弄清楚。

我试图使用的方法是错误的,还是有其他方法可以在Windows手机中进行这种搜索查询?

最值得赞赏的一个例子。

我必须将数据填充回列表框。

嘿,我终于尝试了htmlAgilityPack似乎它一直工作到现在,但我在搜索时得到一个空引用。请帮帮忙。

  private void getPage()
    {
        var wc = new WebClient();
        wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
        wc.DownloadStringAsync(new Uri("http://www.flipkart.com/search-tablets?query=ipad+3"));


    }

    void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();
        html.OptionFixNestedTags = true;
        html.LoadHtml(e.Result);
        var doc = html.DocumentNode.Descendants("div").FirstOrDefault(x => x.Id == "line price-cont");
        String abc = doc.InnerText;


    }

 The html version do contain this kind of tag here is the copied part i want to fetch from the page

   <div>
        <div class="line price-cont ">
            <div class='fk-price line'><span class="price final-price">Rs. 32900</span></div>


        </div>

我尝试搜索span标记,但仍返回null。 任何形式的帮助将不胜感激。 感谢

1 个答案:

答案 0 :(得分:1)

听起来你正在使用正确的方法。要解析XML,我建议使用Linq-to-XML。您将找到关于此主题的大量教程,包括this one which is for Windows Phone specifically

试一试,如果你遇到困难,可以在Stack Overflow中作为一个更具体的问题,包括你的代码。