Php 从外部div获取内容

Php 从外部div获取内容,php,parsing,Php,Parsing,我需要从外部页面获取内容 例如: 让我们使用这个网站:https://en.wikipedia.org/wiki/Main_Page我需要 只有“在这一天…”的内容所以它的意思是带有id=“mp otd”的div 如何使用PHP实现这一点 您可以通过使用PHPDOM解析器来实现这一点 include_once('simple_html_dom.php'); $html = file_get_html('https://en.wikipedia.org/wiki/Main_Page'); $div

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

例如:

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

只有
“在这一天…”的内容
所以它的意思是带有
id=“mp otd”的div


如何使用PHP实现这一点

您可以通过使用
PHPDOM解析器来实现这一点

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); 

需要从下载库

比如说

// 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>';
//从URL或文件创建DOM
$html=file\u get\u html('http://www.google.com/');
//找到具体的
foreach($html->find('div#mp otd')作为$element)
echo$element->innertext'
';
尝试
PHP DOM解析器
使用任何PHP DOM解析器。有很多。