php - 从 PHP 页面中抓取 Price Div 类

标签 php jquery screen-scraping web-scraping scraper

<?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>

上面只是输出:<<<<<<<<<<有人知道为什么会发生这种情况吗?

最佳答案

您有一个语法错误:

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

试试这个:

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

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

<小时/>

试试这个代码:

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

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

关于php - 从 PHP 页面中抓取 Price Div 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7465032/

相关文章:

php - 与 PHP 对话从 Android 应用程序获取命令

jquery - 有没有像 jQuery .is() 这样的谷歌闭包函数

jquery - 在Windows上使用node.js抓取网站

javascript - JQuery css 最大高度不起作用

php - 从 facebook 页面墙或群组墙上获取数据以用于个人网站

python - 用 Python 抓取?

php - 正则表达式:在背景图像 CSS 中查找 URL,遇到问题

php - Laravel 5 在尝试在 View 中输出时如何处理其中包含空格的数据库列名

php - 更改 OpenCart 中的过滤行为

php - 根据距离范围计算速率