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:
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?
$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.