【问题标题】:parse specific data using HtmlAgilityPack使用 HtmlAgilityPack 解析特定数据
【发布时间】:2014-08-06 16:37:21
【问题描述】:

我成功地从 a[@href] 中的网络获取值,但我收到的所有值都不需要。我在网络源中看到我不想要的元素如下:

<a href="http//www.notneeded.com/xxxxxxxxxxxxxgcid=C12289x460&keyword=xxxxxxx">1,507 available from $122</a>"

我需要的所有值都是这样的:

<a href="http//differenturl.com/xxx/xxx/_/id/245/xxxx;xxxx">needed value;M</a>

所有需要的值都是这样开始的:

<a href="http://differenturl.com/xxx/xxx/

然后 id 和值显然与我需要的不同。

请告诉我如何在我将拥有的代码中设置,而不是所有的“a hrefs”,它们的值以“http://differenturl.com/xxx/xxx/”开头的特定a hrefs

对不起我的英语。

代码如下:

var teams = from hyperlink in teamTags.SelectNodes(".//a[@href]")
                    where hyperlink != null
                    select hyperlink.InnerText;

谢谢!

【问题讨论】:

    标签: xml linq parsing html-agility-pack


    【解决方案1】:

    您可以尝试使用XPath starts-with()contains() 函数部分匹配href 属性值,例如:

    .//a[starts-with(@href, 'http://differenturl.com/xxx/xxx/')]
    

    【讨论】:

    • 哥们,你是王者!有效!!!你有没有机会提供在线指导?如果你想赚一些额外的钱,请联系我的电子邮件。再次感谢!
    猜你喜欢
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    • 1970-01-01
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多