簡體   English   中英

使用PHP從另一個網頁檢索表數據

[英]Retrieve table data from another webpage using PHP

我想檢索一些我需要在網頁中以表格格式顯示的數據。

我遵循許多來自stackoverflow的鏈接和解決方案,但我無法獲取任何數據。

以下是我要檢索的數據的URL: http : //www.ip2location.com/demo/1.22.99.222

在上面的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>

這是輸出的屏幕截圖:

1.22.98.173
appstechsolution.in
Apache Phusion_Passenger/4.0.10 mod_bwlimited/1.4 mod_fcgid/2.3.9
HTTP/1.1
Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36
Device Type : PC1.22.98.173Array
ISP : 
City : 
State : 
Country : 
zipcode :

使用simpleHTMLDom,這將加載目標網頁並廢棄所需的表。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM