【问题标题】:grab img src value using HtmlAgilityPack使用 HtmlAgilityPack 获取 img src 值
【发布时间】:2021-04-27 14:14:07
【问题描述】:

我正在尝试使用以下HtmlAgilityPack 获取img src 的值,但这会返回找不到对象的错误。我在这里做错了什么?

c#:

HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(html);

string imgvalue = htmlDoc.DocumentNode.SelectSingleNode("//div[@clsss='a-column a-span3 a-spacing-micro imageThumb thumb']/img").Attributes["src"].Value;

HTML:

<div class="a-column a-span3 a-spacing-micro imageThumb thumb">
<img src="https://images-na.ssl-images-amazon.com/images/I/41RHFEpd-nS._AC_SX60_CR,0,0,60,60_.jpg">
</div>

【问题讨论】:

    标签: c# html-agility-pack


    【解决方案1】:

    将 clss 更改为 class 并重试。应该是work

    HtmlDocument htmlDoc = new HtmlDocument();
    htmlDoc.LoadHtml(html);
    
    string imgvalue = htmlDoc.DocumentNode.SelectSingleNode("//div[@class='a-column a-span3 a-spacing-micro imageThumb thumb']/img").Attributes["src"].Value;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-09
      • 1970-01-01
      • 2015-03-13
      • 1970-01-01
      相关资源
      最近更新 更多