-3

I'm scraping an html page that has X amount of instances of the element class="page-title" inside a div element id="row-1"

So we have something like:

<div id="row-1">
    <div class="page-title">
        <span><h4><a>text I want to grab</a></h4></span>    
    </div>
</div>    

There could be 1,2,3,10 of these rows. Could anyone help explain how I can grab every instance of the page title if there are multiple rows?

bryan
  • 8,879
  • 18
  • 83
  • 166

1 Answers1

3

Whatever you do, don't use a regex! HE COMES

Instead, use a parser:

$dom = new DOMDocument();
$dom->loadHTML($your_html_source_here);
$xpath = new DOMXPath($dom);
$nodes = $xpath->query("//*[@id='row-1']/div[@class='page-title']");
Community
  • 1
  • 1
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592