HtmlAgilityPack - XPath를 사용하여 노드 컬렉션에서 단일 노드 선택

html-agility-pack selectsinglenode xpath

문제

나는 지금 몇 시간 동안이 코드로 싸우고있다 ....

결과의 샘플 노드 :

<div class="left vcard" sizcache="1" sizset="32">
        <h2 class="clearfix fn org url" sizcache="1" sizset="32">
            <a id="listItemTitle_11310540" href="/marcali/viragok-viragkuldes/11310540/ANDOK_MATYAS/hirdetes.mtt">ANDÓK MÁTYÁS</a> <a class="removeFromList" href="#">törlés</a>
        </h2>
        <p class="description">
            2009 decemberében nyitottuk meg az Ezerszirom Virágbolt-ot Marcaliban a Petőfi Sándor u.11-ben. Szeretettel várja a kedves vásárlókat Horváth Györgyike virágkötő, aki 15 éve kápráztatja el kreatíva...</p>
        <ul class="profession" sizcache="1" sizset="34">
            <li sizcache="1" sizset="34"><a href="/szakmak/viragok-viragkuldes/index.mtt">Virágok, virágküldés</a> </li>
        </ul>
        <div class="clearfix margined" sizcache="1" sizset="35">
            <p class="address adr">
                <span>Cím:</span> 8700 Marcali, Petőfi S. utca 11 .</p>
            <ul class="nav clearfix" sizcache="1" sizset="35">
                <li class="mapLink" sizcache="1" sizset="35"><span>-</span><a class="mapLink" href="/terkep/11310540/ANDOK_MATYAS">térképen mutat</a> </li>
                <li class="routeplanner" sizcache="1" sizset="36"><em>útvonaltervezés</em> <span>-</span> <a onclick="window.location = '/redirect.jspv?method=Redirect&amp;routePlanCount=11310540&amp;url=%2Futvonalterv.jspv%3Fto%3D%26from%3D8700+Marcali%2C+Pet%C5%91fi+S.+utca+11+.%26fromX%3D17.414611005499122%26fromY%3D46.57928886409497%26activeTab%3DrouteSearch&amp;activeTab=routeSearch'" href="#">innen</a> <strong>/</strong> <span>-</span> <a onclick="window.location = '/redirect.jspv?method=Redirect&amp;routePlanCount=11310540&amp;url=%2Futvonalterv.jspv%3Ffrom%3D%26to%3D8700+Marcali%2C+Pet%C5%91fi+S.+utca+11+.%26toX%3D17.414611005499122%26toY%3D46.57928886409497%26activeTab%3DrouteSearch'" href="#">ide</a> </li>
            </ul>
            <div class="contacts" sizcache="1" sizset="38">
                <div class="phoneHolder clearfix" sizcache="1" sizset="38">
                    <div class="dt phone">
                        Telefonszám:
                    </div>
                    <div class="dd phoneValue tel" sizcache="1" sizset="38">
                        <span>(70) 326 2843</span> <a class="clickToCall" onclick="javascript:openECS('11310540');" href="#">Hívja ingyen!</a>
                    </div>
                </div>
                <div class="webLinkHolder" sizcache="1" sizset="39">
                    <div class="dt webLink clearfix">
                        Weboldal:
                    </div>
                    <div class="dd webLinkValue" sizcache="1" sizset="39">
                        <a href="http://www.ezerszirom.hu" rel="blank,nofollow">http://www.ezerszirom.hu</a>
                    </div>
                </div>
            </div>
        </div>
    </div>

그리고 내 코드 :

<div class="left vcard" sizcache="1" sizset="32">
        <h2 class="clearfix fn org url" sizcache="1" sizset="32">
            <a id="listItemTitle_11310540" href="/marcali/viragok-viragkuldes/11310540/ANDOK_MATYAS/hirdetes.mtt">ANDÓK MÁTYÁS</a> <a class="removeFromList" href="#">törlés</a>
        </h2>
        <p class="description">
            2009 decemberében nyitottuk meg az Ezerszirom Virágbolt-ot Marcaliban a Petőfi Sándor u.11-ben. Szeretettel várja a kedves vásárlókat Horváth Györgyike virágkötő, aki 15 éve kápráztatja el kreatíva...</p>
        <ul class="profession" sizcache="1" sizset="34">
            <li sizcache="1" sizset="34"><a href="/szakmak/viragok-viragkuldes/index.mtt">Virágok, virágküldés</a> </li>
        </ul>
        <div class="clearfix margined" sizcache="1" sizset="35">
            <p class="address adr">
                <span>Cím:</span> 8700 Marcali, Petőfi S. utca 11 .</p>
            <ul class="nav clearfix" sizcache="1" sizset="35">
                <li class="mapLink" sizcache="1" sizset="35"><span>-</span><a class="mapLink" href="/terkep/11310540/ANDOK_MATYAS">térképen mutat</a> </li>
                <li class="routeplanner" sizcache="1" sizset="36"><em>útvonaltervezés</em> <span>-</span> <a onclick="window.location = '/redirect.jspv?method=Redirect&amp;routePlanCount=11310540&amp;url=%2Futvonalterv.jspv%3Fto%3D%26from%3D8700+Marcali%2C+Pet%C5%91fi+S.+utca+11+.%26fromX%3D17.414611005499122%26fromY%3D46.57928886409497%26activeTab%3DrouteSearch&amp;activeTab=routeSearch'" href="#">innen</a> <strong>/</strong> <span>-</span> <a onclick="window.location = '/redirect.jspv?method=Redirect&amp;routePlanCount=11310540&amp;url=%2Futvonalterv.jspv%3Ffrom%3D%26to%3D8700+Marcali%2C+Pet%C5%91fi+S.+utca+11+.%26toX%3D17.414611005499122%26toY%3D46.57928886409497%26activeTab%3DrouteSearch'" href="#">ide</a> </li>
            </ul>
            <div class="contacts" sizcache="1" sizset="38">
                <div class="phoneHolder clearfix" sizcache="1" sizset="38">
                    <div class="dt phone">
                        Telefonszám:
                    </div>
                    <div class="dd phoneValue tel" sizcache="1" sizset="38">
                        <span>(70) 326 2843</span> <a class="clickToCall" onclick="javascript:openECS('11310540');" href="#">Hívja ingyen!</a>
                    </div>
                </div>
                <div class="webLinkHolder" sizcache="1" sizset="39">
                    <div class="dt webLink clearfix">
                        Weboldal:
                    </div>
                    <div class="dd webLinkValue" sizcache="1" sizset="39">
                        <a href="http://www.ezerszirom.hu" rel="blank,nofollow">http://www.ezerszirom.hu</a>
                    </div>
                </div>
            </div>
        </div>
    </div>

문제? 이후 결과를 반복 오전, 각 노드 자체 설명 있어야하지만 첫 번째 노드의 InnerText 가져 오는. 왜 어떤 생각?

수락 된 답변

XPath에서는 // "재귀 적으로 루트에서 검색"을 의미합니다. 따라서 쿼리는 보유하고있는 노드에서 검색하지는 않지만 문서에서 첫 번째를 가져옵니다.

이 시도:

node.SelectSingleNode("descendant::p[@class='description']")



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