2012-09-30 101 views
0

我想打一個小腳本,我返回的結果取決於多少一個IP地址已經被列入黑名單的IP黑名單。捲曲腳本使用XPATH

結果必須像23/100這意味着23個已列入黑名單的ip或45/1002/100 ...等等。

首先我從http://whatismyipaddress.com/blacklist-check取槽CURL發送POST請求的一些數據:

<?php 
/** 
* Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an 
* array containing the HTTP server response header fields and content. 
*/ 

function get_web_page($url,$argument1) 
{ 
    $options = array(
     CURLOPT_RETURNTRANSFER => true,  // return web page 
     CURLOPT_HEADER   => false, // don't return headers 
     CURLOPT_FOLLOWLOCATION => true,  // follow redirects 
     CURLOPT_ENCODING  => "",  // handle all encodings 
     CURLOPT_USERAGENT  => "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (FM Scene 4.6.1)", // who am i 
     CURLOPT_AUTOREFERER => true,  // set referer on redirect 
     CURLOPT_CONNECTTIMEOUT => 120,  // timeout on connect 
     CURLOPT_TIMEOUT  => 120,  // timeout on response 
     CURLOPT_MAXREDIRS  => 10,  // stop after 10 redirects 
     CURLOPT_POST => 1, 
     CURLOPT_POSTFIELDS => "LOOKUPADDRESS=".$argument1, 
    ); 

    $ch  = curl_init($url); 
    curl_setopt_array($ch, $options); 
    $content = curl_exec($ch); 
    $err  = curl_errno($ch); 
    $errmsg = curl_error($ch); 
    $header = curl_getinfo($ch); 
    curl_close($ch); 

    $header['errno'] = $err; 
    $header['errmsg'] = $errmsg; 
    $header['content'] = $content; 
    return $header; 
} 

echo "<pre>"; 
$result = get_web_page("http://whatismyipaddress.com/blacklist-check","75.122.17.117"); 

// print_r($result['content']); 
// in $result['content'] we have the whole pag 


// Creating xpath and fill it with data 
$doc = new DOMDocument(); 
libxml_use_internal_errors(true); 
$doc->loadHTMLFile($result['content']); // loads your html 
$xpath = new DOMXPath($doc); 

// Get that table 
$value = $xpath->evaluate("string(/html/body/div/div/div/table/text())"); 
echo "Table with blacklists: [$value]\n"; // prints your location 



die; 

?> 

現在我想的是用XPATH /html/body/div/div/div/table/text()並在那裏我看到圖像(!)馬克它列入黑名單解析數據,否則什麼都不要做。

任何人都可以幫助我嗎?

我還觀察到,瀏覽(!)圖片需要一個令牌,我可能會切換到另一個網站,但是我喜歡那個網站,因爲它擁有所有的網站。

謝謝!

回答

0

肯定你需要這個:) Simple DOM Parser

+0

這是一類獨立的PHP庫? – Master345

+0

@RowMinds是的,它是其精彩類讓生活更容易 – Marco

+0

這是一個問題,我將解析這個比較容易,但看一個圖片鏈接是如何'SRC =/blacklist_check.php?BL = web.dnsbl.sorbs.net和IP = 78.96.118.160&記號= 89a5f0e88c2490ed2c53df8ec99725a1'它不像'SRC = bad.png' ... – Master345