2016-06-14 2 views
0

안녕하세요.이 기능을 사용하기 시작했는데 정말 흥미 롭습니다. 어떻게 작동하지 않는지 보지 못하게 되나요?C# HTMLAgility 단일 노드를 선택하십시오. xpath

뭐가 잘못 되었나요? 물론 각 HREF를 선택하려고하지만 그것은 단지 같은 일마다 선택하는하지 않습니다

/shows/1329/fear-the-walking-dead/ 

그것을 선택해야합니다 :

/ep/149658/britains-busiest-airport-heathrow-series-2-1of3-720p-x264-hdtv/ 
/ep/149657/britains-busiest-airport-heathrow-series-2-2of3-720p-x264-hdtv/ 

그래서 이유를 foreach를 사용하는 동일한 노드 만 선택하면 다른 노드가 코드를 heres합니다.

HtmlDocument doc = new HtmlDocument(); 
    doc.LoadHtml("<table align = center border = 0 cellpadding = 0 cellspacing = 0 class=forum_header_border width = 950 ><tr>< td class=section_post_header colspan = 12 >< h1 style=display:inline>EZTV Series Torrents</h1>-<h2 style = display:inline><i>Watch & Download TV Series on EZTV</i></h2><tr><td class=forum_thread_header width = 35 title=\"Show Information\">Info<td class=forum_thread_header style=text-align:left;padding-left:10px>Episode Name<td class=forum_thread_header>Downloads<td class=forum_thread_header>Size<td class=forum_thread_header>Released<td class=forum_thread_header_end>Forum<tr class=forum_space_border><td class=header_date colspan=6>Added on: <b>23, August, 2015</b><tr class=forum_header_border name=hover><td class=forum_thread_post width=35><a href=/shows/1329/fear-the-walking-dead/ title=\"Fear the Walking Dead Torrent\"><img alt=Show border=0 src=/ezimg/s/1/3/show_info.png title=\"Show Description about Fear the Walking Dead\"></a><a href=http://www.tvmaze.com/episodes/185233/fear-the-walking-dead-1x01-pilot title=\"More info about Fear The Walking Dead S01E01 HDTV x264-KILLERS [eztv] at tvmaze.com\"onclick='return trackOutboundLink(\"http://www.tvmaze.com/episodes/185233/fear-the-walking-dead-1x01-pilot\"),!1'target=_blank><img alt=TVmaze border=0 src=/images/tvmaze-16x16.png height=16 width=16></a><td class=forum_thread_post><a href=/ep/149661/fear-the-walking-dead-s01e01-hdtv-x264-killers/ title=\"Fear The Walking Dead S01E01 HDTV x264-KILLERS [eztv] (472.60 MB)\"class=epinfo alt=\"Fear The Walking Dead S01E01 HDTV x264-KILLERS [eztv] (472.60 MB)\">Fear The Walking Dead S01E01 HDTV x264-KILLERS [eztv]</a><td class=forum_thread_post align=center><a href=\"magnet:?xt=urn:btih:701bfe400e248707ac3fe94dce46bed49baedea2&dn=Fear.The.Walking.Dead.S01E01.HDTV.x264-KILLERS.mp4%5Beztv%5D&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A80&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969\"title=\"Fear The Walking Dead S01E01 HDTV x264-KILLERS [eztv] (472.60 MB) Magnet Link\"rel=nofollow class=magnet></a> <a href=https://zoink.ch/torrent/Fear.The.Walking.Dead.S01E01.HDTV.x264-KILLERS.mp4[eztv].torrent title=\"Fear The Walking Dead S01E01 HDTV x264-KILLERS Torrent: Download Mirror #1\"rel=nofollow class=download_1></a><td class=forum_thread_post align=center>472.60 MB<td class=forum_thread_post align=center>9 mo<td class=forum_thread_post_end align=center><a href=/forum/discuss/149661/ title=\"Discuss about Fear The Walking Dead S01E01 HDTV x264-KILLERS [eztv]:\"rel=nofollow><img alt=Discuss border=0 src=/ezimg/s/1/3/chat_empty.png title=\"Discuss about this show\"height=16 width=16></a><tr class=forum_space_border><td class=header_date colspan=6>Added on: <b>16, May, 2016</b><tr class=forum_header_border name=hover><td class=forum_thread_post width=35><a href=/shows/1329/fear-the-walking-dead/ title=\"Fear the Walking Dead Torrent\"><img alt=Show border=0 src=/ezimg/s/1/3/show_info.png title=\"Show Description about Fear the Walking Dead\"></a><a href=http://www.tvmaze.com/episodes/664693/fear-the-walking-dead-2x06-sicut-cervus title=\"More info about Fear the Walking Dead S02E06 HDTV x264-FLEET [eztv] at tvmaze.com\"onclick='return trackOutboundLink(\"http://www.tvmaze.com/episodes/664693/fear-the-walking-dead-2x06-sicut-cervus\"),!1'target=_blank><img alt=TVmaze border=0 src=/images/tvmaze-16x16.png height=16 width=16></a><td class=forum_thread_post><a href=/ep/149660/fear-the-walking-dead-s02e06-hdtv-x264-fleet/ title=\"Fear the Walking Dead S02E06 HDTV x264-FLEET [eztv] (291.48 MB)\"class=epinfo alt=\"Fear the Walking Dead S02E06 HDTV x264-FLEET [eztv] (291.48 MB)\">Fear the Walking Dead S02E06 HDTV x264-FLEET [eztv]</a><td class=forum_thread_post align=center><a href=\"magnet:?xt=urn:btih:a69a1660f62c6bfea040ad479046ec9f685a6cdf&dn=Fear.the.Walking.Dead.S02E06.HDTV.x264-FLEET%5Beztv%5D.mkv%5Beztv%5D&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A80&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969\"title=\"Fear the Walking Dead S02E06 HDTV x264-FLEET [eztv] (291.48 MB) Magnet Link\"rel=nofollow class=magnet></a> <a href=https://zoink.ch/torrent/Fear.the.Walking.Dead.S02E06.HDTV.x264-FLEET[eztv].mkv.torrent title=\"Fear the Walking Dead S02E06 HDTV x264-FLEET Torrent: Download Mirror #1\"rel=nofollow class=download_1></a> <a href=\"https://zoink.ch/mirror/Fear the Walking Dead S02E06 HDTV x264-FLEET [eztv.ag] [alt].torrent\"title=\"Fear the Walking Dead S02E06 HDTV x264-FLEET Torrent: Download Mirror #3\"rel=nofollow class=download_3></a><td class=forum_thread_post align=center>291.48 MB<td class=forum_thread_post align=center>3 weeks<td class=forum_thread_post_end align=center><a href=/forum/discuss/149660/ title=\"Discuss about Fear the Walking Dead S02E06 HDTV x264-FLEET [eztv]:\"rel=nofollow><img alt=Discuss border=0 src=/ezimg/s/1/3/chat_empty.png title=\"Discuss about this show\"height=16 width=16></a><tr class=forum_space_border><td class=header_date colspan=6>Added on: <b>10, April, 2016</b><tr class=forum_header_border name=hover><td class=forum_thread_post width=35><a href=/shows/1329/fear-the-walking-dead/ title=\"Fear the Walking Dead Torrent\"><img alt=Show border=0 src=/ezimg/s/1/3/show_info.png title=\"Show Description about Fear the Walking Dead\"></a><a href=http://www.tvmaze.com/episodes/562186/fear-the-walking-dead-2x01-monster title=\"More info about Fear The Walking Dead S02E01 720p HDTV x264-SVA [eztv] at tvmaze.com\"onclick='return trackOutboundLink(\"http://www.tvmaze.com/episodes/562186/fear-the-walking-dead-2x01-monster\"),!1'target=_blank><img alt=TVmaze border=0 src=/images/tvmaze-16x16.png height=16 width=16></a><td class=forum_thread_post><a href=/ep/149659/fear-the-walking-dead-s02e01-720p-hdtv-x264-sva/ title=\"Fear The Walking Dead S02E01 720p HDTV x264-SVA [eztv] (1.18 GB)\"class=epinfo alt=\"Fear The Walking Dead S02E01 720p HDTV x264-SVA [eztv] (1.18 GB)\">Fear The Walking Dead S02E01 720p HDTV x264-SVA [eztv]</a><td class=forum_thread_post align=center><a href=\"magnet:?xt=urn:btih:98119bd8514b88f834aa8f1e5f3dbfab89b7ac4e&dn=Fear.The.Walking.Dead.S02E01.720p.HDTV.x264-SVA%5Beztv%5D.mkv%5Beztv%5D&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A80&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969\"title=\"Fear The Walking Dead S02E01 720p HDTV x264-SVA [eztv] (1.18 GB) Magnet Link\"rel=nofollow class=magnet></a> <a href=https://zoink.ch/torrent/Fear.The.Walking.Dead.S02E01.720p.HDTV.x264-SVA[eztv].mkv.torrent title=\"Fear The Walking Dead S02E01 720p HDTV x264-SVA Torrent: Download Mirror #1\"rel=nofollow class=download_1></a> <a href=\"https://zoink.ch/mirror/Fear The Walking Dead S02E01 720p HDTV x264-SVA [eztv.ag] [alt].torrent\"title=\"Fear The Walking Dead S02E01 720p HDTV x264-SVA Torrent: Download Mirror #3\"rel=nofollow class=download_3></a><td class=forum_thread_post align=center>1.18 GB<td class=forum_thread_post align=center>2 mo<td class=forum_thread_post_end align=center><a href=/forum/discuss/149659/ title=\"Discuss about Fear The Walking Dead S02E01 720p HDTV x264-SVA [eztv]:\"rel=nofollow><img alt=Discuss border=0 src=/ezimg/s/1/3/chat_empty.png title=\"Discuss about this show\"height=16 width=16></a><tr class=forum_space_border><td class=header_date colspan=6>Added on: <b>14, June, 2016</b><tr class=forum_header_border name=hover><td class=forum_thread_post width=35><a href=/shows/187/mv-group-documentaries/ title=\"MV Group Documentaries Torrent\"><img alt=Show border=0 src=/ezimg/s/1/3/show_info.png title=\"Show Description about MV Group Documentaries\"></a><td class=forum_thread_post><a href=/ep/149658/britains-busiest-airport-heathrow-series-2-1of3-720p-x264-hdtv/ title=\"Britains Busiest Airport Heathrow Series 2 1of3 720p x264 HDTV [eztv] (959.94 MB)\"class=epinfo alt=\"Britains Busiest Airport Heathrow Series 2 1of3 720p x264 HDTV [eztv] (959.94 MB)\">Britains Busiest Airport Heathrow Series 2 1of3 720p x264 HDTV [eztv]</a><td class=forum_thread_post align=center><a href=\"magnet:?xt=urn:btih:601564318faeda0f760fe7cacd346928573101ac&dn=Britains.Busiest.Airport.Heathrow.Series.2.1of3.720p.x264.HDTV%5Beztv%5D.mp4%5Beztv%5D&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A80&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969\"title=\"Britains Busiest Airport Heathrow Series 2 1of3 720p x264 HDTV [eztv] (959.94 MB) Magnet Link\"rel=nofollow class=magnet></a> <a href=https://zoink.ch/torrent/Britains.Busiest.Airport.Heathrow.Series.2.1of3.720p.x264.HDTV[eztv].mp4.torrent title=\"Britains Busiest Airport Heathrow Series 2 1of3 720p x264 HDTV Torrent: Download Mirror #1\"rel=nofollow class=download_1></a><td class=forum_thread_post align=center>959.94 MB<td class=forum_thread_post align=center>46m 29s<td class=forum_thread_post_end align=center><a href=/forum/discuss/149658/ title=\"Discuss about Britains Busiest Airport Heathrow Series 2 1of3 720p x264 HDTV [eztv]:\"rel=nofollow><img alt=Discuss border=0 src=/ezimg/s/1/3/chat_empty.png title=\"Discuss about this show\"height=16 width=16></a><tr class=forum_header_border name=hover><td class=forum_thread_post width=35><a href=/shows/187/mv-group-documentaries/ title=\"MV Group Documentaries Torrent\"><img alt=Show border=0 src=/ezimg/s/1/3/show_info.png title=\"Show Description about MV Group Documentaries\"></a><td class=forum_thread_post><a href=/ep/149657/britains-busiest-airport-heathrow-series-2-2of3-720p-x264-hdtv/ title=\"Britains Busiest Airport Heathrow Series 2 2of3 720p x264 HDTV [eztv] (1022.12 MB)\"class=epinfo alt=\"Britains Busiest Airport Heathrow Series 2 2of3 720p x264 HDTV [eztv] (1022.12 MB)\">Britains Busiest Airport Heathrow Series 2 2of3 720p x264 HDTV [eztv]</a><td class=forum_thread_post align=center><a href=\"magnet:?xt=urn:btih:92f98f7e01e8cbc00e4bf69d50480b7601629a15&dn=Britains.Busiest.Airport.Heathrow.Series.2.2of3.720p.x264.HDTV%5Beztv%5D.mp4%5Beztv%5D&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A80&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969\"title=\"Britains Busiest Airport Heathrow Series 2 2of3 720p x264 HDTV [eztv] (1022.12 MB) Magnet Link\"rel=nofollow class=magnet></a> <a href=https://zoink.ch/torrent/Britains.Busiest.Airport.Heathrow.Series.2.2of3.720p.x264.HDTV[eztv].mp4.torrent title=\"Britains Busiest Airport Heathrow Series 2 2of3 720p x264 HDTV Torrent: Download Mirror #1\"rel=nofollow class=download_1></a><td class=forum_thread_post align=center>1022.12 MB<td class=forum_thread_post align=center>46m 29s<td class=forum_thread_post_end align=center><a href=/forum/discuss/149657/ title=\"Discuss about Britains Busiest Airport Heathrow Series 2 2of3 720p x264 HDTV [eztv]:\"rel=nofollow><img alt=Discuss border=0 src=/ezimg/s/1/3/chat_empty.png title=\"Discuss about this show\"height=16 width=16></a><tr class=forum_header_border name=hover><td class=forum_thread_post width=35><a href=/shows/187/mv-group-documentaries/ title=\"MV Group Documentaries Torrent\"><img alt=Show border=0 src=/ezimg/s/1/3/show_info.png title=\"Show Description about MV Group Documentaries\"></a><td class=forum_thread_post><a href=/ep/149656/britains-busiest-airport-heathrow-series-2-3of3-720p-x264-hdtv/ title=\"Britains Busiest Airport Heathrow Series 2 3of3 720p x264 HDTV [eztv] (1015.86 MB)\"class=epinfo alt=\"Britains Busiest Airport Heathrow Series 2 3of3 720p x264 HDTV [eztv] (1015.86 MB)\">Britains Busiest Airport Heathrow Series 2 3of3 720p x264 HDTV [eztv]</a><td class=forum_thread_post align=center><a href=\"magnet:?xt=urn:btih:cefd247ecc034bf7121920321f8320600d1a34ba&dn=Britains+Busiest+Airport+Heathrow+Series+2+3of3+720p+x264+HDTV+%5Beztv%5D&tr=udp%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2710%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=http%3A%2F%2Fwww.mvgroup.org%3A2710%2Fannounce\"title=\"Britains Busiest Airport Heathrow Series 2 3of3 720p x264 HDTV Torrent: Magnet Link\"rel=nofollow class=magnet></a> <a href=\"https://zoink.ch/mirror/Britains Busiest Airport Heathrow Series 2 3of3 720p x264 HDTV [eztv.ag] [alt].torrent\"title=\"Britains Busiest Airport Heathrow Series 2 3of3 720p x264 HDTV Torrent: Download Mirror #3\"rel=nofollow class=download_3></a><td class=forum_thread_post align=center>1015.86 MB<td class=forum_thread_post align=center>46m 29s<td class=forum_thread_post_end align=center><a href=/forum/discuss/149656/ title=\"Discuss about Britains Busiest Airport Heathrow Series 2 3of3 720p x264 HDTV [eztv]:\"rel=nofollow><img alt=Discuss border=0 src=/ezimg/s/1/3/chat_empty.png title=\"Discuss about this show\"height=16 width=16></a></tr><td class=forum_thread_post_end align=center><a href=/forum/discuss/149612/ title=\"Discuss about Reign S03E17 HDTV x264-FLEET [eztv]:\"rel=nofollow><img alt=Discuss border=0 src=/ezimg/s/1/3/chat_empty.png title=\"Discuss about this show\"height=16 width=16></a></table>"); 
    var node = doc.DocumentNode.SelectSingleNode("//table[@class='forum_header_border']"); 
    var nodes = node.SelectNodes("//td[@class='forum_thread_post']"); 

    foreach (HtmlNode tdNode in nodes) 
    { 
     HtmlNode aNode = tdNode.SelectSingleNode("//a[@href]"); 
     Console.WriteLine(aNode.Attributes["href"].Value); 
    } 

    Console.ReadKey(); 

cano 수정을 게시하고 혼란 스럽기 때문에 설명해주세요.

대단히 고마워요.

답변

1

"//"표현 앞에 "." XML 검색 엔진에 현재 노드 참조와 관련된 검색을 실행하도록 지시합니다.

그래서 그 대신이

HtmlNode aNode = tdNode.SelectSingleNode("//a[@href]"); 

이 작업을 수행 :

HtmlNode aNode = tdNode.SelectSingleNode(".//a[@href]"); 

Xpath examples

// 저자 : 문서의 모든 요소를.

.// 제목 : 현재 모든 요소가 하나 이상의 수준으로 현재 컨텍스트에 있습니다.

+0

답장을 보내 주셔서 감사합니다. – Wexo

관련 문제