htmlagilitypack 구문 분석 (ID없는 테이블) vb.net

html html-agility-pack html-table vb.net xpath

문제

희망이 당신에게서 몇 가지 답변을 얻을.

vb.net 및 htmlagilitypack을 사용하여 데이터를 가져오고 작동하지만 원하는 방식이 아님)

나는이 html 페이지 (의 일부) :


<TABLE WITH=100% BORDER=4>

<TR>
<TH><A HREF="http:/cgi-bin/vplata.py?tgnr=4300&val=Visa+T%C3%A5gnummer&Bek=Visa&sort=Lok" >Lok</A></TH>
<TH><A HREF="http:/cgi-bin/vplata.py?tgnr=4300&val=Visa+T%C3%A5gnummer&Bek=Visa&sort=Avg" >Avg&aring;r</A></TH>
<TH><A HREF="http:/cgi-bin/vplata.py?tgnr=4300&val=Visa+T%C3%A5gnummer&Bek=Visa&sort=AvgS" >Station</A></TH>
<TH><A HREF="http:/cgi-bin/vplata.py?tgnr=4300&val=Visa+T%C3%A5gnummer&Bek=Visa&sort=Ank" >Ankommer</A></TH>
<TH><A HREF="http:/cgi-bin/vplata.py?tgnr=4300&val=Visa+T%C3%A5gnummer&Bek=Visa&sort=AnkS" >Station</A></TH>
<TH>Tjänstetyp</TH>
</TR>
<TR>
<TD><a HREF="/cgi-bin/vplata.py?individ=R1176&val=Visa+Lokindivid&Bek=Visa">R1176</a></TD>
<TD>Mar-20-2013 13:04:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=HBGB&val=Visa+Driftplats&Bek=Visa">HBGB</A></TD>
<TD>Mar-20-2013 21:21:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=ET3&val=Visa+Driftplats&Bek=Visa">ET3</A></TD>
<TD>B1</TD>
</TR>
<TR>
<TD><a HREF="/cgi-bin/vplata.py?individ=R1267&val=Visa+Lokindivid&Bek=Visa">R1267</a></TD>
<TD>Mar-20-2013 13:04:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=HBGB&val=Visa+Driftplats&Bek=Visa">HBGB</A></TD>
<TD>Mar-20-2013 21:21:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=ET3&val=Visa+Driftplats&Bek=Visa">ET3</A></TD>
<TD>B2</TD>
</TR>
<TR>
<TD><a HREF="/cgi-bin/vplata.py?individ=R1267&val=Visa+Lokindivid&Bek=Visa">R1267</a></TD>
<TD>Mar-20-2013 22:05:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=ET3&val=Visa+Driftplats&Bek=Visa">ET3</A></TD>
<TD>Mar-20-2013 22:28:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=KB%&val=Visa+Driftplats&Bek=Visa">KBÄ</A></TD>
<TD>D1</TD>
</TR>
<TR>
<TD><a HREF="/cgi-bin/vplata.py?individ=R1281&val=Visa+Lokindivid&Bek=Visa">R1281</a></TD>
<TD>Mar-21-2013 13:04:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=HBGB&val=Visa+Driftplats&Bek=Visa">HBGB</A></TD>
<TD>Mar-21-2013 21:21:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=ET3&val=Visa+Driftplats&Bek=Visa">ET3</A></TD>
<TD>D1</TD>
</TR>
<TR>
<TD><a HREF="/cgi-bin/vplata.py?individ=R1281&val=Visa+Lokindivid&Bek=Visa">R1281</a></TD>
<TD>Mar-21-2013 22:05:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=ET3&val=Visa+Driftplats&Bek=Visa">ET3</A></TD>
<TD>Mar-21-2013 22:28:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=KB%&val=Visa+Driftplats&Bek=Visa">KBÄ</A></TD>
<TD>B2</TD>
</TR>
<TR>
<TD><a HREF="/cgi-bin/vplata.py?individ=RXXXXX&val=Visa+Lokindivid&Bek=Visa">RXXXXX</a></TD>
<TD>Mar-21-2013 22:05:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=ET3&val=Visa+Driftplats&Bek=Visa">ET3</A></TD>
<TD>Mar-21-2013 22:28:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=KB%&val=Visa+Driftplats&Bek=Visa">KBÄ</A></TD>
<TD>B1\B2</TD>
</TR>
<TR>
<TD><a HREF="/cgi-bin/vplata.py?individ=R1281&val=Visa+Lokindivid&Bek=Visa">R1281</a></TD>
<TD>Mar-25-2013 13:04:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=HBGB&val=Visa+Driftplats&Bek=Visa">HBGB</A></TD>
<TD>Mar-25-2013 21:21:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=ET3&val=Visa+Driftplats&Bek=Visa">ET3</A></TD>
<TD>D1</TD>
</TR>
<TR>
<TD><a HREF="/cgi-bin/vplata.py?individ=R1281&val=Visa+Lokindivid&Bek=Visa">R1281</a></TD>
<TD>Mar-25-2013 22:05:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=ET3&val=Visa+Driftplats&Bek=Visa">ET3</A></TD>
<TD>Mar-25-2013 22:28:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=KB%&val=Visa+Driftplats&Bek=Visa">KBÄ</A></TD>
<TD>D1</TD>
</TR>
<TR>
<TD><a HREF="/cgi-bin/vplata.py?individ=R1254&val=Visa+Lokindivid&Bek=Visa">R1254</a></TD>
<TD>Mar-27-2013 13:04:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=HBGB&val=Visa+Driftplats&Bek=Visa">HBGB</A></TD>
<TD>Mar-27-2013 21:21:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=ET3&val=Visa+Driftplats&Bek=Visa">ET3</A></TD>
<TD>B2</TD>
</TR>
<TR>
<TD><a HREF="/cgi-bin/vplata.py?individ=RXXXXX&val=Visa+Lokindivid&Bek=Visa">RXXXXX</a></TD>
<TD>Mar-27-2013 13:04:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=HBGB&val=Visa+Driftplats&Bek=Visa">HBGB</A></TD>
<TD>Mar-27-2013 21:21:00</TD>
<TD><A HREF="/cgi-bin/vplata.py?stn=ET3&val=Visa+Driftplats&Bek=Visa">ET3</A></TD>
<TD>B1\B2</TD>
</TR>
</TABLE>
<A><A>Senast uppdaterad: Mar-20-2013 18:16:00</A><BR>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<TR>
<TD width="20%" bgcolor="#009900"  align="left">
<IMG src="http://litmgc101.greencargo.com/bottenbild.jpg" alt="Green Cargo" width=800 height=25 border=0>
</TD>
</TR>
<TR>
</table>

내가하고 싶은 일은 "R1176"과 "Mar-20-2013 13:04:00"으로 부품을 가져 오는 것입니다. (시간이 "13:04:00"이 아니라는 것을 선호합니다), 나중에 VB.net에서 파싱 단계에서 건너 뛸 수 없으면 삭제할 수 있습니다.

그래서 내가하고 싶은 일을 간단히 설명하면 다음과 같습니다 : 모든 "R1234"와 함께 제공된 날짜를 가져 와서 "R4321"을위한 텍스트 상자와 날짜 또는 다른 텍스트 상자를 말하게하십시오.

수락 된 답변

C #에서는 다음과 같은 작업을 수행합니다.

var result =
    doc.DocumentNode.SelectNodes("//td/a[contains(@href,'Lokindivid')]")
       .Select(node => new KeyValuePair<string, DateTime>(node.InnerText, DateTime.Parse(node.SelectSingleNode("./ancestor::tr[1]/td[2]").InnerText).Date));

내 VB.NET foo는 제공 한 샘플 html로 작동하는 다음 코드 (리터럴 번역본)를 생성했습니다.

var result =
    doc.DocumentNode.SelectNodes("//td/a[contains(@href,'Lokindivid')]")
       .Select(node => new KeyValuePair<string, DateTime>(node.InnerText, DateTime.Parse(node.SelectSingleNode("./ancestor::tr[1]/td[2]").InnerText).Date));



아래 라이선스: CC-BY-SA with attribution
와 제휴하지 않음 Stack Overflow
이 KB는 합법적입니까? 예, 이유를 알아보십시오.
아래 라이선스: CC-BY-SA with attribution
와 제휴하지 않음 Stack Overflow
이 KB는 합법적입니까? 예, 이유를 알아보십시오.