<?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>
以上只是输出:<<<<<<<<<<
任何人都知道为什么会发生这种情况?
答案 0 :(得分:1)
您遇到语法错误:
$items = $html->find('div[class=psliprice]"');
请改为尝试:
$items = $html->find('div[class="psliprice"]');
另外(我可能错了),Google是否有针对此类请求的API?
请尝试使用此代码:
$Prices[] = $post->children(0)->outertext;
然后移除echo $item[1];
行。