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"]');

また(私は間違っているかもしれません)、GoogleはそのようなリクエストのためのAPIを持っていませんか?


代わりにこのコードを試してください:

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

そして、そのecho $item[1];行を削除します。

于 2011-09-18T23:01:24.853 に答える