简体   繁体   English

RSS提要Ebay C#

[英]Rss feed Ebay c#

I am currently using the code 我目前正在使用代码

     string[] toSearch = { "title", "link", "description" };
        string url = "http://www.ebay.co.uk/sch/i.html?_sacat=0&_from=R40&_nkw=" + itemToSearch.Replace(" ", "+") + "&_sop=15&_rss=1";
        WebRequest request = WebRequest.Create(url);
        WebResponse responce = request.GetResponse();
        Stream rssStream = responce.GetResponseStream();
        XmlDocument rssDocument = new XmlDocument();
        rssDocument.Load(rssStream);
        XmlNodeList rssItems = rssDocument.SelectNodes("channel/item");
        int xMax = toSearch.Length;
        int yMax = rssItems.Count;
        String[,] tempRssData = new String[yMax + 1, xMax];
        for (int i = 0; i < rssItems.Count; ++i)
        {
            XmlNode rssNode = null;
            for (int ii = 0; ii < toSearch.Length; ++ii)
            {
                rssNode = rssItems.Item(i).SelectSingleNode(toSearch[ii]);
                if (rssNode != null)
                {
                    tempRssData[i, ii] = rssNode.InnerText;
                }
                else
                {
                    tempRssData[i, ii] = "";
                }
            }
        }

but rssItems.Count = 0, Does anyone know why. 但是rssItems.Count = 0,有人知道为什么。 the example of the rss feed I am using is http://www.ebay.co.uk/sch/i.html?_sacat=0&_from=R40&_nkw=raspberry+pi&_sop=15&_rss=1 我使用的RSS提要示例是http://www.ebay.co.uk/sch/i.html?_sacat=0&_from=R40&_nkw=raspberry+pi&_sop=15&_rss=1

Your XPath is wrong. 您的XPath错误。

I would suggest you learn how to use XPath correctly by inspecting the XPath spec and looking at tutorials online. 我建议您通过检查XPath 规范并在线查看教程来学习如何正确使用XPath。

To fix the problem, you will need to change: 要解决此问题,您需要进行以下更改:

XmlNodeList rssItems = rssDocument.SelectNodes("channel/item");

to: 至:

XmlNodeList rssItems = rssDocument.SelectNodes("//channel/item");

You can also execute XPath queries natively in Chrome. 您也可以在Chrome中本地执行XPath查询。 Open your RSS feed page in Chrome, open the Developer Tools, open the Console and type in: 在Chrome中打开RSS供稿页面,打开开发人员工具,打开控制台,然后输入:

$x("expression")

so it becomes: 变成:

$x("channel/item")

Which, you should notice, returns nothing. 您应该注意,这什么都不返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM