0

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?

1
  • Are there limitations in the parser (for size or supported elements)? Or does the page of the post contain errors (whereas the main does not)? Commented May 20, 2013 at 20:56

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.