Search code examples
phphtmlweb-scrapingxpath

Scraping <h2> inside a <div>


Just having some trouble scraping the h2 on this code:

<div id="content">
    <div class="title-wrapper">
        <article class="article">
        <figure>
            <a title="Ölüm Denizi" href="http://trfilmizle.com/olum-denizi.html">
                <img class="small-poster" alt="Ölüm Denizi" src="http://i706.photobucket.com/albums/ww64/ddizi/TRfilmizle/OumlluumlmDenizi_zpsc809f300.jpg~original">
            </a>
        </figure>
    <div class="article-container">
    <h2>
        <a title="Ölüm Denizi" href="http://trfilmizle.com/olum-denizi.html">Ölüm Denizi</a>
    </h2>
    <div class="article-info">
    <div class="description"> Kuzey Kore, Güney Kore ve Çin arasına sıkışmış Yanji kentinde geçen Ölüm Denizi, araba kovalamacaları, cinayetler ve bıçaklı kavgalarla dolu… </div>
</div>

Any idea? I can access the nodes via:

//article[@class='article']/text()

But, can't get the h2! Any suggestions?


Solution

  • This should get all of the text components underneath h2 elements in the divs:

    //div/h2//*/text()
    

    More specifically, you can limit it to specific divs:

    //div[@class='article-container']/h2//*/text()