Comment gratter <div class="content" id ="getSch"> en utilisant HtmlAgilityPack C #

asp.net c# html html-agility-pack

Question

Je veux gratter les données du site de cinéma dans lesquelles je voudrais supprimer le calendrier et le titre du film. Je ne sais pas comment écrire une requête pour supprimer ce code HTML <div class="content" id="getSh"> .

<div class="container">
          <div class="content" id="getSh"><ul class="ctr"><li class="ctrl">Cinema 1</li>
          <li class="ctrr">09, Mar</li><li class="cl"></li></ul>
          <ul class="col_row"><li class="col"><a href="#">3:15 pm</a></li>
          <li class="col cb"><a href="/movies/detail/299">The Second Best Exotic Marigold Hotel 
          <span class="blue">Digital 2D</span></a></li><li class="col cc"><a href="#">--</a>
          </li><li class="cl"></li></ul> <ul class="col_row"><li class="col"><a href="#">6:15 pm</a
          li><li class="col cb"><a href="/movies/detail/307">Focus <span class="blue">Digital 2D
          </span><span class="red">Adults Only</span></a></li><li class="col cc"><a href="#">--
          </a></li><li class="cl"></li></ul> <ul class="col_row"><li class="col">
          <a href="#">8:45 pm</a></li><li class="col cb"><a href="/movies/detail/266">
          Kingsman: The Secret Service <span class="blue">Digital 2D</span><span class="red">
          Adults Only</span></a></li><li class="col cc"><a href="#">--</a></li><li class="cl">
          </li></ul><ul class="col_row col_m"><li class="col"><a href="#">11:45 pm</a></li>
          <li class="col cb"><a href="/movies/detail/267">Badlapur <span class="blue">Digital 2D
          </span></a></li><li class="col cc"><a href="#">--</a></li><li class="cl">
          </li></ul><ul class="ctr"><li class="ctrl">Cinema 2</li><li class="ctrr">09, Mar</li>
          <li class="cl"></li></ul> <ul class="col_row"><li class="col"><a href="#">3:30 pm</a>
          </li><li class="col cb"><a href="/movies/detail/307">Focus <span class="blue">Digital 
          </span><span class="red">Adults Only</span></a></li><li class="col cc"><a href="#">--<
          /a></li><li class="cl"></li></ul> <ul class="col_row"><li class="col"><a href="#">6:00
          pm</a></li><li class="col cb"><a href="/movies/detail/266">Kingsman: The Secret Service
          <span class="blue">Digital 2D</span><span class="red">Adults Only</span></a></li>
          <li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul> <ul class="col_row">
          <li class="col"><a href="#">9:00 pm</a></li><li class="col cb"><a href="/movies/detail/307">
          Focus <span class="blue">Digital 2D</span><span class="red">Adults Only</span></a></li>
          <li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul><ul class="col_row col_m">
          <li class="col"><a href="#">11:30 pm</a></li><li class="col cb"><a href="/movies/detail/266">
          Kingsman: The Secret Service <span class="blue">Digital 2D</span><span class="red">Adults Only
          </span></a></li><li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul><ul class="
          ctr"><li class="ctrl">Cinema 3</li><li class="ctrr">09, Mar</li><li class="cl"></li></ul>
          <ul class="col_row"><li class="col"><a href="#">3:45 pm</a></li><li class="col cb"><
          a href="/movies/detail/321">Hey Bro <span class="blue">Digital 2D</span></a></li><
          li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul> <ul class="col_row"><
          li class="col"><a href="#">6:30 pm</a></li><li class="col cb"><a href="/movies/detail/328">D
          irty Politics <span class="blue">Digital 2D</span><span class="red">Adults Only</span>
          </a></li><li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul> 
          <ul class="col_row"><li class="col"><a href="#">9:30 pm</a></li><li class="col cb">
          <a href="/movies/detail/321">Hey Bro <span class="blue">Digital 2D</span></a></li><
          li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul><ul class="col_row col_m">
          <li class="col"><a href="#">12:15 am</a></li><li class="col cb"><a href="/movies/detail/328"
          >Dirty Politics <span class="blue">Digital 2D</span><span class="red">Adults Only</span></a>

          </li><li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul><ul class="ctr">
          <li class="ctrl">Cinema 4</li><li class="ctrr">09, Mar</li><li class="cl"></li></ul> 
          <ul class="col_row"><li class="col"><a href="#">3:00 pm</a></li><li class="col cb">
          <a href="/movies/detail/295">The SpongeBob Movie: Sponge Out of Water  <span class="blue">D
          igital 3D</span></a></li><li class="col cc"><a href="#">--</a></li><li class="cl"></li>
          </ul> <ul class="col_row"><li class="col"><a href="#">5:15 pm</a></li><li class="col cb">
          <a href="/movies/detail/300">Paddington <span class="blue">Digital 2D</span></a></li>
          <li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul> <ul class="col_row"><
          li class="col"><a href="#">7:30 pm</a></li><li class="col cb"><a href="/movies/detail/297">
          Unbroken <span class="blue">Digital 2D</span></a></li><li class="col cc"><a href="#">--</a>
          </li><li class="cl"></li></ul><ul class="col_row col_m"><li class="col"><a href="#">10:30 pm
          </a></li><li class="col cb">
          <a href="/movies/detail/299">The Second Best Exotic Marigold Hotel <span class="blue">Digital 2D<
          /span></a></li><li class="col cc"><
          a href="#">--</a></li><li class="cl"></li></ul><ul class="ctr">
          <li class="ctrl">Royal Cinema</li><li class="ctrr">09, Mar</li>
          <li class="cl"></li></ul> <ul class="col_row"><li class="col"><
          a href="#">3:05 pm</a></li><li class="col cb"><a href="/movies/detail/328">Dirty Politics <
          span class="blue">Digital 2D</span><span class="red">Adults Only</span></a></li><li class="col cc">
          <a href="#">--</a></li><li class="cl"></li></ul> <ul class="col_row"><li class="col"><a href="#">
          6:05 pm</a></li><li class="col cb"><a href="/movies/detail/307">Focus <span class="blue">Digital 2D
          </span><span class="red">Adults Only</span></a></li><li class="col cc"><a href="#">--</a></li>
          <li class="cl"></li></ul><ul class="col_row col_m"><li class="col"><a href="#">8:30 pm</a></li>
          <li class="col cb"><a href="/movies/detail/299">The Second Best Exotic Marigold Hotel
          <span class="blue">Digital 2D</span></a></li><li class="col cc"><a href="#">--</a></li>
          <li class="cl"></li></ul></div>
        </div>

Et j'utilise ce code C # pour extraire des données qui ne fonctionnent pas

<div class="container">
          <div class="content" id="getSh"><ul class="ctr"><li class="ctrl">Cinema 1</li>
          <li class="ctrr">09, Mar</li><li class="cl"></li></ul>
          <ul class="col_row"><li class="col"><a href="#">3:15 pm</a></li>
          <li class="col cb"><a href="/movies/detail/299">The Second Best Exotic Marigold Hotel 
          <span class="blue">Digital 2D</span></a></li><li class="col cc"><a href="#">--</a>
          </li><li class="cl"></li></ul> <ul class="col_row"><li class="col"><a href="#">6:15 pm</a
          li><li class="col cb"><a href="/movies/detail/307">Focus <span class="blue">Digital 2D
          </span><span class="red">Adults Only</span></a></li><li class="col cc"><a href="#">--
          </a></li><li class="cl"></li></ul> <ul class="col_row"><li class="col">
          <a href="#">8:45 pm</a></li><li class="col cb"><a href="/movies/detail/266">
          Kingsman: The Secret Service <span class="blue">Digital 2D</span><span class="red">
          Adults Only</span></a></li><li class="col cc"><a href="#">--</a></li><li class="cl">
          </li></ul><ul class="col_row col_m"><li class="col"><a href="#">11:45 pm</a></li>
          <li class="col cb"><a href="/movies/detail/267">Badlapur <span class="blue">Digital 2D
          </span></a></li><li class="col cc"><a href="#">--</a></li><li class="cl">
          </li></ul><ul class="ctr"><li class="ctrl">Cinema 2</li><li class="ctrr">09, Mar</li>
          <li class="cl"></li></ul> <ul class="col_row"><li class="col"><a href="#">3:30 pm</a>
          </li><li class="col cb"><a href="/movies/detail/307">Focus <span class="blue">Digital 
          </span><span class="red">Adults Only</span></a></li><li class="col cc"><a href="#">--<
          /a></li><li class="cl"></li></ul> <ul class="col_row"><li class="col"><a href="#">6:00
          pm</a></li><li class="col cb"><a href="/movies/detail/266">Kingsman: The Secret Service
          <span class="blue">Digital 2D</span><span class="red">Adults Only</span></a></li>
          <li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul> <ul class="col_row">
          <li class="col"><a href="#">9:00 pm</a></li><li class="col cb"><a href="/movies/detail/307">
          Focus <span class="blue">Digital 2D</span><span class="red">Adults Only</span></a></li>
          <li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul><ul class="col_row col_m">
          <li class="col"><a href="#">11:30 pm</a></li><li class="col cb"><a href="/movies/detail/266">
          Kingsman: The Secret Service <span class="blue">Digital 2D</span><span class="red">Adults Only
          </span></a></li><li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul><ul class="
          ctr"><li class="ctrl">Cinema 3</li><li class="ctrr">09, Mar</li><li class="cl"></li></ul>
          <ul class="col_row"><li class="col"><a href="#">3:45 pm</a></li><li class="col cb"><
          a href="/movies/detail/321">Hey Bro <span class="blue">Digital 2D</span></a></li><
          li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul> <ul class="col_row"><
          li class="col"><a href="#">6:30 pm</a></li><li class="col cb"><a href="/movies/detail/328">D
          irty Politics <span class="blue">Digital 2D</span><span class="red">Adults Only</span>
          </a></li><li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul> 
          <ul class="col_row"><li class="col"><a href="#">9:30 pm</a></li><li class="col cb">
          <a href="/movies/detail/321">Hey Bro <span class="blue">Digital 2D</span></a></li><
          li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul><ul class="col_row col_m">
          <li class="col"><a href="#">12:15 am</a></li><li class="col cb"><a href="/movies/detail/328"
          >Dirty Politics <span class="blue">Digital 2D</span><span class="red">Adults Only</span></a>

          </li><li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul><ul class="ctr">
          <li class="ctrl">Cinema 4</li><li class="ctrr">09, Mar</li><li class="cl"></li></ul> 
          <ul class="col_row"><li class="col"><a href="#">3:00 pm</a></li><li class="col cb">
          <a href="/movies/detail/295">The SpongeBob Movie: Sponge Out of Water  <span class="blue">D
          igital 3D</span></a></li><li class="col cc"><a href="#">--</a></li><li class="cl"></li>
          </ul> <ul class="col_row"><li class="col"><a href="#">5:15 pm</a></li><li class="col cb">
          <a href="/movies/detail/300">Paddington <span class="blue">Digital 2D</span></a></li>
          <li class="col cc"><a href="#">--</a></li><li class="cl"></li></ul> <ul class="col_row"><
          li class="col"><a href="#">7:30 pm</a></li><li class="col cb"><a href="/movies/detail/297">
          Unbroken <span class="blue">Digital 2D</span></a></li><li class="col cc"><a href="#">--</a>
          </li><li class="cl"></li></ul><ul class="col_row col_m"><li class="col"><a href="#">10:30 pm
          </a></li><li class="col cb">
          <a href="/movies/detail/299">The Second Best Exotic Marigold Hotel <span class="blue">Digital 2D<
          /span></a></li><li class="col cc"><
          a href="#">--</a></li><li class="cl"></li></ul><ul class="ctr">
          <li class="ctrl">Royal Cinema</li><li class="ctrr">09, Mar</li>
          <li class="cl"></li></ul> <ul class="col_row"><li class="col"><
          a href="#">3:05 pm</a></li><li class="col cb"><a href="/movies/detail/328">Dirty Politics <
          span class="blue">Digital 2D</span><span class="red">Adults Only</span></a></li><li class="col cc">
          <a href="#">--</a></li><li class="cl"></li></ul> <ul class="col_row"><li class="col"><a href="#">
          6:05 pm</a></li><li class="col cb"><a href="/movies/detail/307">Focus <span class="blue">Digital 2D
          </span><span class="red">Adults Only</span></a></li><li class="col cc"><a href="#">--</a></li>
          <li class="cl"></li></ul><ul class="col_row col_m"><li class="col"><a href="#">8:30 pm</a></li>
          <li class="col cb"><a href="/movies/detail/299">The Second Best Exotic Marigold Hotel
          <span class="blue">Digital 2D</span></a></li><li class="col cc"><a href="#">--</a></li>
          <li class="cl"></li></ul></div>
        </div>

Je veux cette sortie Salle de cinéma = Cinéma 1 Nom du film = Le deuxième meilleur hôtel Marigold exotique et son horaire

Réponse acceptée

D'après ce que j'ai compris, vous essayez d'obtenir le nom du film? Si c'est le cas, le code ci-dessous devrait faire ceci:

    foreach (HtmlNode heading in htmlNode.SelectNodes("//ul[@class='col_row']")
    {
        var heading = heading.SelectSingleNode(".//li[@class='col cb']/a").InnerText;
        //I Presume you want other fields here?
    }



Sous licence: CC-BY-SA with attribution
Non affilié à Stack Overflow
Est-ce KB légal? Oui, apprenez pourquoi
Sous licence: CC-BY-SA with attribution
Non affilié à Stack Overflow
Est-ce KB légal? Oui, apprenez pourquoi