0

我想制作一个小脚本,根据 ip 被列入黑名单的数量返回结果。

结果必须像23/10023 已将该 ip 或45/100 2/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()并且我看到图像(!)将其标记为黑名单,否则什么也不做。

谁能帮我?

我还观察到查看(!)图像需要一个令牌,我可能会切换到另一个站点,但我喜欢那个特定的网站,因为它拥有所有的网站。

谢谢!

4

1 回答 1

0

绝对你需要这个:) 简单的 DOM 解析器

于 2012-09-30T14:37:47.633 回答