Reputation: 595
I am using the open source PHP library known as PHP Simple HTML DOM Parser to scrape the first image of a Wordpress Post. If I call the main website:
$html = file_get_html('http://iadorefood.com/');
I get a response, an object of the DOM that I can manipulate. But if I request the URL of a specific post, my object returns NULL. Here is my command:
$html = file_get_html('http://iadorefood.com/articles/tuscany-san-gimignano/');
Why does my object return NULL? Is there something wrong with the URL?
Upvotes: 0
Views: 1968
Reputation: 146191
Try this
include('simple_html_dom.php');
$html = file_get_html('http://iadorefood.com/articles/tuscany-san-gimignano');
$element = $html->find('div.content p img');
echo '<img src=' . $element[0]->src . ' />';
It's tested and working, notice the trailing /
at the URL, I've removed it and works fine.
Upvotes: 2