Search code examples
phphtmlparsingdomscreen-scraping

DOMNode could not be converted into a string


<?php
// try this html listing example for all nodes / includes a few getElementsByTagName options:

$file = $DOCUMENT_ROOT. "http://website.com";
$doc = new DOMDocument();
@$doc->loadHTMLFile($file);

// example 1:
$elements = $doc->getElementsByTagName('tr');

$album = $elements->item(1);

echo $album;

How am I able to convert this into data that I can output to the screen? It says I cannot convert into a string. I have read that the DOMnode doesn't function like an array, but it makes a DOMNodeList.


Solution

  • Check out the examples from this page

    http://www.php.net/manual/en/domnodelist.item.php

    Use

    $album->nodeValue