使用asp.net获取div标签内的内部html和内部文本 [英] Fetch inner html and inner text within a div tag using asp.net
问题描述
我正在使用Html Agility Pack来获取我需要的内部html和内部文本代码。这是html页面代码。
i am using Html Agility Pack to fetch my require inner html and inner text code. here is the html page code.
<div id="product-info-shipping" class="product-info-shipping-pnl util-clearfix notranslate" data-widget-cid="widget-14">US $6.98
<span class="shipping-to">to</span></span><span id="shipping-country">United States</span>
<span class="shipping-via">via</span>
<span id="shipping-company">DHL</span></a>
来自我使用的代码:
from code behind i used this:
HtmlWeb web = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.Load(txt.Text);
HtmlNode rateNode = doc.DocumentNode.SelectSingleNode("//div[@id='product-info-shipping']");
string rate = rateNode.InnerText;
但它只接受该div中的文本。我想采取所有的HTML代码,包括该div中的文本。请事先告诉我如何做到这一点
but it only takes text within that div. and i want to take all the html code including text within that div. Please tell me how to do this thanks in advance
推荐答案
6.98
< span class = shipping-to > 到< / span > < / span > < span id = shipping-country > 美国< / span >
< span class = shipping-via > 来自 < / span >
< span id = shipping-company > DHL < / span > < / a >
6.98 <span class="shipping-to">to</span></span><span id="shipping-country">United States</span> <span class="shipping-via">via</span> <span id="shipping-company">DHL</span></a>
来自我使用的代码:
from code behind i used this:
HtmlWeb web = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.Load(txt.Text);
HtmlNode rateNode = doc.DocumentNode.SelectSingleNode("//div[@id='product-info-shipping']");
string rate = rateNode.InnerText;
但它只接受该div中的文本。我想采取所有的HTML代码,包括该div中的文本。请事先告诉我如何做到这一点
but it only takes text within that div. and i want to take all the html code including text within that div. Please tell me how to do this thanks in advance
这篇关于使用asp.net获取div标签内的内部html和内部文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!