使用文件获取内容从电子商务网站获取产品价格



我正在尝试使用php和file_get_contents函数来获取产品价格。这是我的密码。它正在加载整个页面,但是我只需要这个页面的价格。有人能帮忙吗?感谢

<?php
$homepage = file_get_contents('https://www.snapdeal.com/product/bhawna-collection-loard-shiv-trishul/672311651336');
echo $homepage;
?>

PHP简单HTML DOM解析器是这类东西的天赐之物

在这里获取代码

只需将其包含在您的php 中即可

require_once('./path/to/SimpleHtmlDom.php');
// Create DOM from URL or file
$html = file_get_html('https://www.snapdeal.com/product/bhawna-collection-loard-shiv-trishul/672311651336');
// Find all images
$price = $html->find('.pdp-final-price .payBlkBig', 0)->plaintext;

更多关于这个很棒的工具

使用标准功能

<?php

$homepage = file_get_contents('https://www.snapdeal.com/product/bhawna-collection-loard-shiv-trishul/672311651336');
$search = '<span class="payBlkBig"  itemprop="price">';
$subStrPos = strpos($homepage, $substring) + strlen($search);
$subStr = substr($string, $subStrPos);
$price = substr($subStr, 0, strpos($subs, '</span>'));

echo $price;

相关内容

最新更新