Search code examples
phpmetaquerypath

QueryPath (PHP) and meta tags


Does anyone have any examples of how to scrape meta tags using QueryPath? I'm trying to get the content of the following:

<meta content="London" property="og:locality">

I recently switched from simple_html_dom which was easy to use, well documented BUT slow. In comparison QueryPath is faster, but has crap documentation and very few questions on Google / SO.


Solution

  • Just use:

    $locality = qp($html)->find('meta[property="og:locality"]')->attr("content");
    

    Where $html is the html page you want to parse. $locality would have the value London based on your given example.

    Here's a good general tutorial: http://www.ibm.com/developerworks/web/library/os-php-querypath/index.html