2
<?php

    # don't forget the library
    include('simple_html_dom.php');

    # this is the global array we fill with article information
    $Prices = array();

    getPrices('http://www.google.com/search?q=xbox+360&tbm=shop&hl=en&aq=f');

function getPrices($page) {
    global $Prices, $descriptions;

    $html = new simple_html_dom();
    $html->load_file($page);

    $items = $html->find('div.psliprice');   

    foreach($items as $post) {
        # remember comments count as nodes
        $Prices[] = $post->children(0)->outertext;
    }
}

?>


<html>
<head>
    <style>
        #main {
            margin: 80px auto;
            width: 600px;
        }
        h1 {
            font: bold20px/30px verdana, sans-serif;
            text-decoration: none;
        }
        p {
            font: 10px/14px verdana, sans-serif;
    </style>
</head>
<body>
    <div id="main">
<?php
    foreach($Prices as $item) {
        echo $item[0];
        #echo $item[1];
    }
?>
    </div>
</body>
</html>

以上只是输出:<<<<<<<<<<有人知道为什么会这样吗?

4

1 回答 1

1

你有一个语法错误:

$items = $html->find('div[class=psliprice]"');

试试这个:

$items = $html->find('div[class="psliprice"]');

另外(我可能错了),谷歌没有针对此类请求的 API 吗?


试试这个代码:

$Prices[] = $post->children(0)->outertext;

并删除echo $item[1];线。

于 2011-09-18T23:01:24.853 回答