[英]Split values by tag <br> HtmlAgility
I get the value from ChildNode.InnerHtml as 我从ChildNode.InnerHtml获得值
20th Aug 2013<br>Ojas Systems <br> Pune <br> Software
How to split the values from generated InnerHtml by HtmlAgilty. 如何通过HtmlAgilty从生成的InnerHtml中拆分值。 I tried converting InnerHtml to string, but it throws an error 我尝试将InnerHtml转换为字符串,但是会引发错误
No overload for method 'Write' takes 0 arguments 方法'Write'的重载不接受0个参数
may be because of unclosed html tags but then what could be the solution Below is the returned InnerHtml 可能是由于未关闭的html标记,但是可能是什么解决方案,下面是返回的InnerHtml
<a href="http://jobs.monsterindia.com/details/13826093.html?sig=js-1- 4f08ba3c3102de443076cfb01e15745e-1&from=" target="_blank" id="link13826093">.Net java </a>, 20th Aug 2013<br>Ojas Systems Private Limited<br> Pune, 0-0 years: Looking for freshers who is trained in .Net Java.The location will be Pune.Preferably passed in 2012-2013. <br><a href="javascript:findSimilar(13826093)">Similar Jobs</a> - <a href="http://jobsearch.monsterindia.com/searchresult.html?cid=117314;lan=1">All Jobs by this Recruiter</a> - <a href="javascript:void(0)" onclick="javascript:openSocialTwist({EXP:'Experience - 0 to 0 years',LINK:'http://jobs.monsterindia.com/details/13826093.html',COMP:'Company Name - Ojas Systems Private Limited',LOC:'Location - Pune',ROLE:'',KWD:'Key skills - .net java',TTL:'Job Title - .Net java '})">Share this job</a>
If you able to retrieve ChildNode.InnerHtml you also should be able to save it as a string: 如果您能够检索ChildNode.InnerHtml,则还应该能够将其另存为字符串:
string inner_html = ChildNode.InnerHtml.ToString();
You could replace <br>
with "/" or some other char ( inner_html .replace("<br>,"/")
) and then use simple string split on "/" char 您可以将<br>
替换为“ /”或其他一些char( inner_html .replace("<br>,"/")
),然后在” /“ char上使用简单的字符串拆分
EDIT : 编辑 :
If the innerhtml will always be in the same format you could go with something like this 如果innerhtml始终采用相同的格式,则可以使用如下所示的格式
string[] delimiter = new string[] {"<br>"};
string inner_html = ChildNode.InnerHtml.ToString();
int i = inner_html.IndexOf("</a>");
if( i!=-1)
{
int j = inner_html.IndexOf("<a", i + 4);
if (j != -1)
{
string yourStr = inner_html.Substring(i + 4,j);
string[] splitedStr = yourStr.split(delimiter, StringSplitOptions.RemoveEmptyEntries);
}
}
string input = "20th Aug 2013<br>Ojas Systems <br> Pune <br> Software";
string[] result = input.Split(new string[]{"<br>"}, StringSplitOptions.None);
Output 输出量
20th Aug 2013
Ojas Systems
Pune
Software
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.