0

我想从网站上获取可用产品文件名和配置文件序列号的信息。

如果总是有新的序列号和下面的过程显示 html 代码,我是如何刮掉产品序列号的?

<pre> <td><b>product file number </b> 7269</td  </pre> 
<pre> <td><b>product file number </b> 7562</td> </pre> 
<pre> <td><b>product file number </b> 7502</td> </pre>

我是新的 Windows 窗体应用程序区域,所以请提供完整的代码以获得良好的帮助。如果你能帮助我,我真的很高兴。

4

1 回答 1

0

您可以将数据视为 XML

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication45
{
    class Program
    {
        static void Main(string[] args)
        {
            string input =
               "<pre> <td><b>product file number </b> 7269</td>  </pre>" +
               "<pre> <td><b>product file number </b> 7562</td> </pre>" +
               "<pre> <td><b>product file number </b> 7502</td> </pre>";

            //add root tag around data so you have only one root tag
            input = string.Format("<Root>{0}</Root>", input);

            XElement root = XElement.Parse(input);
            var products = root.Descendants("pre").Select(x => new {
                name = x.Descendants("b").FirstOrDefault().Value,
                number = int.Parse(x.Element("td").Nodes().Skip(1).Take(1).FirstOrDefault().ToString())
            }).ToList();


        }

    }

}
于 2015-09-02T01:13:29.643 回答