php抓取网页连接函数(我想从其他网站获取所有时间表的航班数据.. )
优采云 发布时间: 2021-10-19 14:17php抓取网页连接函数(我想从其他网站获取所有时间表的航班数据..
)
我的 网站 有问题。我想从其他网站 获取所有时刻表的航班数据。我查看了它的源代码并获得了用于处理数据的 url 链接。有人可以告诉我如何从当前 url 链接中获取数据并将其显示在我们的 网站 上?
您可以使用 file_get_contents() 函数来完成此操作。此函数返回所提供 URL 的 html。然后使用 HTML Parser 获取所需数据。
$html = file_get_contents("http://website.com");
$dom = new DOMDocument();
$dom->loadHTML($html);
$nodes = $dom->getElementsByTagName('h3');
foreach ($nodes as $node) {
echo $node->nodeValue."
"; // return tag data
}
另一种使用 preg_match_all() 提取数据的方法
$html = file_get_contents($_REQUEST['url']);
preg_match_all('/(.*?)/s', $html, $matches);
// specify the class to get the data of that class
foreach ($matches[1] as $node) {
echo $node."
";
}