如何使用PHP从网页中获取特定数据

如何使用PHP从网页中获取特定数据,php,regex,Php,Regex,我试图使用PHP和file_get_内容以及正则表达式从网页中获取数据,但似乎无法从网页中获取正确的数据 这是我的密码 <?php $homepage = file_get_contents('http://www.website.com'); preg_match_all('/<p><b>(.*)<\ /b><br>(.*)<br>(.*)<\ /p>/ms', $homepage, $matches);

我试图使用PHP和file_get_内容以及正则表达式从网页中获取数据,但似乎无法从网页中获取正确的数据

这是我的密码

<?php
   $homepage = file_get_contents('http://www.website.com');
   preg_match_all('/<p><b>(.*)<\ /b><br>(.*)<br>(.*)<\ /p>/ms', $homepage, $matches);
   $def = $matches[0];
   echo $def;
   ?>

我的正则表达式没有拾取任何内容,即使存在与表达式匹配的html代码。作为测试,我还尝试用下面的函数替换第一个preg_match函数

preg_match_all('/<div>(.*)<\ /div>/ms', $homepage, $matches);
preg_match_all('/(.*)/ms',$homepage,$matches);
这只拾取了页面上许多div标记中的2个。我的代码有什么问题,应该以什么样的正确方式编写


谢谢

不用正则表达式,只需使用PHP的

(参考表格问题)

$homepage = file_get_contents('http://www.website.com');
$DOM = new DOMDocument;
$DOM->loadHTML($homepage);
$items = $DOM->getElementsByTagName('div');
$def = $items->item(0)->nodeValue;