Pergunta

I want to extract price of given envato product - http://codecanyon.net/item/ftp-cloud/7610011 Till now I have been upto this :-

<?php
$url = "http://codecanyon.net/item/ftp-cloud/7610011";
$html = file_get_contents_curl($url);

function get_price($html)
{
$price = "";
$dom = new DOMDocument();   
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$xpath = new DOMXPath($dom);                
$divs_price = $xpath->query('//strong[@class="purchase-form__price js-purchase-price"]');
//print_r($divs_price);
foreach ($divs_price as $price_data) 
{
$price = trim(innerHTML($price_data));
if($price!="")
return $price;
}

return $price;
}

$price = get_price($html);
echo $price;

But still I am getting no response in my php output. ADDED:I have used this

function file_get_contents_curl($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
Foi útil?

Solução

file_get_contents_curl is not a function. Did you try something like this:

$html = download($url);

function download($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$data = curl_exec($ch);
curl_close($ch);
unset($ch);
return $data;
}

function get_price($html)
{
$pattern = '/<strong class="purchase-form__price js-purchase-price">(.*?)<\/strong>/s';
preg_match_all($pattern, $html, $result);
return trim($result[1][0]);
}

Outras dicas

Not sure why you are not using the Envato API it fetches prices nicely

http://marketplace.envato.com/api/documentation

here's the code if you like

   $ch1 = curl_init();  
   curl_setopt($ch1, CURLOPT_URL, 'http://marketplace.envato.com/api/edge/item-prices:'.$itemid.'.json');  
   curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, 50);  
    curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true); 
    $ch_data1 = curl_exec($ch1);  
    $json_data1 = json_decode($ch_data1, true);

    $price = $json_data1['item-prices']['0']['price'];

    curl_close($ch1); 

it does not even need your envato api key. itemid is the item id of codecanyon item.

code taken from http://codecanyon.net/item/sixthlife-search-for-envato-affiliates/7614796

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top