1

Given a page's contents (its HTML), how could I get the contents of the article?

For example, this website returns the contents of articles given a URL:

http://embed.ly/docs/explore/extract?url=http%3A%2F%2Fwww.foxnews.com%2Fsports%2F2016%2F08%2F14%2Fryan-lochte-3-other-u-s-swimmers-robbed-in-brazil.html

However, I don't want to use their API. I've used file_get_contents($url), but I have no idea how I would go about getting the contents of just the article.

Any ideas?

1 Answers1

3
$url = 'http://www.foxnews.com/sports/2016/08/14/ryan-lochte-3-other-u-s-swimmers-robbed-in-brazil.html';
$content = file_get_contents($url);
$first_step = explode( '<div class="article-text">' , $content );
$paras = explode("<p>" , $first_step[1] );

foreach($paras as $para ) {
   echo $para;
}

here if you want to get contents with image also use article tag as used in their dom structure.

owais
  • 4,752
  • 5
  • 31
  • 41