需要从多个站点获取div的内容
我想获取 newegg 的产品价格。这是此网站的一个示例网站
http://www.newegg.com/Product/Product.aspx?Item=**N82E16820167027**
,我想获取包含价格的
的内容。我不太擅长制作代码,所以我在网上搜索代码并用它作为示例来制作我自己的...这是到目前为止的结果:
function getprice($itemId) {
$source=trim("http://www.newegg.com/Product/Product.aspx?Item=".$itemId);
preg_match("'<div class=\"grpPricing\">(.*?)</div>'si", $source, $match);
if($match)
echo "result=".$match[1];
}
给出了 $itemId
,这就是如何我可以制作一个脚本,循环遍历多个 newegg 产品并获取所需的信息
注意:它不会让我发布真正应该的代码,不知道为什么,也许是因为我没有注册?!
还有另一个我无法解决的问题...代码的输出应该是:
return strip_tags($price);
只是因为稍后我会用这行调用该函数,
$price=getprice($row['newegg_productid']);
我尽力解释清楚,但如果您无法理解,请告诉我。非常感谢任何帮助,谢谢!
I would like to grab the prices of products from newegg. heres an example site
http://www.newegg.com/Product/Product.aspx?Item=**N82E16820167027**
from this site, i would like to get the content of <div class="grpPricing">
, that contains the price.
im not very skilled at making codes, so i was searching the web for codes and used it as an example to make my own... heres the result so far:
function getprice($itemId) {
$source=trim("http://www.newegg.com/Product/Product.aspx?Item=".$itemId);
preg_match("'<div class=\"grpPricing\">(.*?)</div>'si", $source, $match);
if($match)
echo "result=".$match[1];
}
$itemId
is given, this is how i can make a script that loops through multiple newegg products and gets the needed info
NOTE: it wont let me post the code as it really should be, dont know why, maybe because im not registered?!
and theres another issue that i cant solve... the output of the code should be:
return strip_tags($price);
simply because later i would call the function with this line
$price=getprice($row['newegg_productid']);
ive tried my best to explain clearly, but let me know if you have trouble understanding. any help is much appreciated, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了您的领先地位:
For your headstart: