DOMXPath::Evaluate with CSS classes

123 views Asked by At

I'm creating a script to retrieve prices from a specific product URL.

Here is my script so far:

<?php

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "http://www.something.com/someproduct.html");
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);

$content = curl_exec($ch);

$dom = new DOMDocument();
$internalErrors = libxml_use_internal_errors(true);
$dom->loadHTML( $content );

libxml_use_internal_errors($internalErrors);


$xpath = new DOMXpath($dom);

$price  = $xpath->evaluate("string(//strong[@class='new-price'])");
echo $preco;

My doubt is: I there a way where I can remove the strong tag and still find the value under the "new-price" class?

Like: $price = $xpath->evaluate("string(//[@class='new-price'])"); ?

Hope for some help! Thanks.

0

There are 0 answers