C#으로 htmlagilitypack을 사용하여 HTML 파서를 일반화하는 방법에 대한 제안이 필요합니다. 구문 분석 한 웹 페이지에는 직원 정보가 들어 있습니다. 그들 모두가) 이름, ID, 주소를 가지고, 여기에 전화 은 시간 d)를 작동 또는) 이메일 B) 팩스 C 표시되지 않을 수있는 필드) skypeid 있습니다C#에서 htmlagilitypack을 사용하여 다양한 HTML 구문 분석
Employee 1
<table>
<tr><td nowrap>Name</td><td class="title"><b>Amy</b></td></tr><tr>
<tr><td nowrap>ID</td><td class="title"><b>12345</b></td></tr><tr>
<tr><td nowrap>Address</td><td class="title"><b>36 Main St, Baton Rouge, LA</b></td></tr><tr>
<tr><td nowrap>Telephone</td><td class="title"><b>123-456-7890</b></td></tr><tr>
<tr><td nowrap>Email</td><td class="title"><b>[email protected]</b></td></tr><tr>
<tr><td>skypeid</td><td class="title"><b>oilcompany</b></td></tr><tr>
</table>
Employee 2
<table>
<tr><td nowrap>Name</td><td class="title"><b>Cathy</b></td></tr><tr>
<tr><td nowrap>ID</td><td class="title"><b>99345</b></td></tr><tr>
<tr><td nowrap>Address</td><td class="title"><b>36 Main St, Baton Rouge, LA</b></td></tr><tr>
<tr><td nowrap>Telephone</td><td class="title"><b>123-456-7899</b></td></tr><tr>
<tr><td nowrap>Working Hours</td><td class="title"><b>8 PM - 6 AM</b></td></tr><tr>
<tr><td nowrap>fax</td><td class="title"><b>123-456-1111</b></td></tr><tr>
</table>
코드 :
HtmlNodeCollection tdNoWraps = hdoc.DocumentNode.SelectNodes("//td[@nowrap]");
HtmlNodeCollection tdNoWrapsclass = hdoc.DocumentNode.SelectNodes("//td[@class]");
if(tdNoWraps != null)
{
if (tdNoWraps[0].InnerText.Trim().Contains("Name"))
dr["Name"] = tdNoWrapsclass[0].InnerText.Trim();
....
}
Employee 1이 Employee와 다릅니다. 어떻게 일반 구문 분석기를 작성할 수 있습니까? 또한 'skypeid'태그가 없습니다.
감사 HR