gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 05:04:01 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com