伙计我正在尝试做的是我在下面列出了一段html代码。我需要锚标记内的内容。 [英] Guys what i'm trying to do is I've a section of a html code listed below. I need the content within the anchor tag.

查看:90
本文介绍了伙计我正在尝试做的是我在下面列出了一段html代码。我需要锚标记内的内容。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计我正在尝试做的是我在下面列出了一段html代码。我需要锚标记内的内容。

 HtmlDocument newHtml = new HtmlDocument(); 
newHtml.OptionOutputAsXml = true;

var content =< div class = business-名称容器 >
< span class = tier_info > < / span >
< h3 class = title fn org >
< a href = http://www.abc.com/nationwide/mip/xyz?lid=161004592 class = url link > Foo < / a >
< / h3 >
< / div > ;

newHtml.Load(content);
HtmlNode doc = newHtml.DocumentNode;
var findContent = doc.SelectNodes(// a [@ class ='url link']);
foreach(在findContent中var aContent)
{
if(content.InnerHtml!= null)
{
Console.WriteLine(Content:+ content.InnerHtml );
}
}

但我没有得到结果。
我希望输出为Content:Foo

解决方案

试试这段代码。我没有在机器上测试这段代码,但这可能对你有帮助。

  var  links = top.document。 getElementsByTagName('  a'); 
var result = [];
var linkcount = links.length;
for var i = 0 ; i < linkcount; i ++){
if (links [i]。 InnerHtml!= null ;){
alert(links [i] .InnerHtml)
}
}


Guys what i'm trying to do is I've a section of a html code listed below. I need the content within the anchor tag.

HtmlDocument newHtml = new HtmlDocument();
newHtml.OptionOutputAsXml = true;

var content = "<div class="business-name-container">
                <span class="tier_info"></span>
                    <h3 class="title fn org">
                        <a href="http://www.abc.com/nationwide/mip/xyz?lid=161004592" class="url link">Foo</a>
                    </h3>
                </div>";

newHtml.Load(content);
HtmlNode doc = newHtml.DocumentNode;
var findContent = doc.SelectNodes("//a[@class='url link']");
foreach (var aContent in findContent)
{
    if (content.InnerHtml != null)
    {
           Console.WriteLine("Content: " + content.InnerHtml);
    }
}

But i'm not getting the results.
I want to the output to be as "Content : Foo"

解决方案

Try this code. Iam not tested this code on machine but this may help you.

var links = top.document.getElementsByTagName('a');
var result = [];
var linkcount = links.length;
for ( var i = 0; i < linkcount; i++) {
    if (links[i].InnerHtml!= null;) {
        alert(links[i].InnerHtml)
    }
}


这篇关于伙计我正在尝试做的是我在下面列出了一段html代码。我需要锚标记内的内容。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆