使用PHP从另一个网页检索表数据

使用PHP从另一个网页检索表数据,php,html,file-get-contents,preg-match-all,information-retrieval,Php,Html,File Get Contents,Preg Match All,Information Retrieval,我想以表格格式检索我需要的网页中的一些数据。 我关注stackoverflow的许多链接和解决方案,但我无法获得任何数据。 下面是我要检索数据的URL: 在上面的URL中,有一个我想要得到的信息表 请提供检索数据的代码 先谢谢你 这是代码。我不能从这个代码中得到任何错误。也无法获取正则表达式筛选器代码的输出 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1

我想以表格格式检索我需要的网页中的一些数据。

我关注stackoverflow的许多链接和解决方案,但我无法获得任何数据。

下面是我要检索数据的URL:

在上面的URL中,有一个我想要得到的信息表

请提供检索数据的代码

先谢谢你

这是代码。我不能从这个代码中得到任何错误。也无法获取正则表达式筛选器代码的输出

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome To MY Page</title>
</head>
<body>
<div class="signform">
<?php
// Function to get the client ip address
echo "<br/>".$_SERVER['REMOTE_ADDR'];
echo "<br/>".$_SERVER['SERVER_NAME'];
echo "<br/>".$_SERVER['SERVER_SOFTWARE'];
echo "<br/>".$_SERVER['SERVER_PROTOCOL'];
echo "<br/>".$_SERVER['ALL_HTTP'];
echo "<br/>".$_SERVER['HTTP_USER_AGENT']."<br/>";
// These lines are mandatory.
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;

// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
echo "Device Type : Mobile";

}
// Any tablet device.
else if( $detect->isTablet() ){
echo "Device Type : Tablet";
}
else {
echo "Device Type : PC";
}
$ip = $_SERVER['REMOTE_ADDR'];
echo $ip;
$content = file_get_contents("http://www.ip2location.com/demo/$ip");
preg_match_all('/<body>(.*?)<\/body>/s',$content,$output,PREG_SET_ORDER);
echo $output;
echo "<br/> ISP : ".$isp."<br/> City : ".$city."<br/> State : ".$state."<br/> Country : ".$country."<br/> zipcode : ".$zipcode;
?>
</div>
</body>
</html>
使用此选项将加载目标网页并废弃所需的表

include_once('classes/simple_html_dom.php');
$html = file_get_html('http://www.ip2location.com/demo/1.22.99.222');
echo $html->find("#main-content .table", 0);

您好,用户2940072,欢迎使用堆栈溢出。请阅读提问指南:您的桌子的结构是什么?你想从中得到什么数据?您已经编写了哪些代码来获取它?您有什么问题?您好,谢谢您的建议,并向我学习如何使用stac koverflow。现在也请提供解决方案。该网站提供了一个php模块供您下载和使用,而不是试图刮网页:感谢您对模块的建议。我已经知道了。若我使用模块来获取数据,那个么我需要77MB的数据库包。这很难。可以使用上述方法帮助获取数据。比如从其他页面获取数据。
include_once('classes/simple_html_dom.php');
$html = file_get_html('http://www.ip2location.com/demo/1.22.99.222');
echo $html->find("#main-content .table", 0);