2016-03-02 111 views
0

我需要从外部页面获取内容。从外部div获取内容

例如:

让我们使用这个网站:https://en.wikipedia.org/wiki/Main_Page我需要得到

只有"On this day..."内容,因此这意味着格与id="mp-otd"

我如何能做到这一点用PHP?

+1

尝试'PHP DOM parser' – Noman

+0

使用任何PHP DOM解析器的。有很多这些。 – mehulmpt

回答

0

您可以通过起诉PHP DOM parser

include_once('simple_html_dom.php'); 
$html = file_get_html('https://en.wikipedia.org/wiki/Main_Page'); 
$div_content = $html->find('div[id=mp-otd]', 0); 
0

需要从http://simplehtmldom.sourceforge.net/

下载库例如为此

// Create DOM from URL or file 
$html = file_get_html('http://www.google.com/'); 

// Find specific 
foreach($html->find('div #mp-otd') as $element) 
     echo $element->innertext . '<br>';