0
給定一個頁面的內容(它的HTML),我怎麼能得到文章的內容?獲取文章內容URL
例如,該網站返回給定URL文章內容:
不過,我並不想用自己的API。我已經使用file_get_contents($url)
,但我不知道如何去獲取的內容只是文章。
任何想法?
給定一個頁面的內容(它的HTML),我怎麼能得到文章的內容?獲取文章內容URL
例如,該網站返回給定URL文章內容:
不過,我並不想用自己的API。我已經使用file_get_contents($url)
,但我不知道如何去獲取的內容只是文章。
任何想法?
$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;
}
在這裏,如果你想獲得圖像的內容也使用文章標籤在他們的dom結構中使用。
希望'article-text'裏面沒有'div'。 – chris85
你將不得不解析'file_get_contents($ url)'的輸出,並保留你感興趣的部分。 –
如何正則表達式或substr,strstr,strpos,....函數 –
@OrryVandermeulen不,使用內置的解析器。 – chris85