I'm parsing an html document and I need to extract all the prices in it (the format is $99.00). So what I want to do is extract all the elements that contain the substring "Price" (or "price") in its class or id attribute. But I tried using something like $("[class*='Price']") or $("[id*='Price']") and then concatenate the results on an array but the jquery selector part is not working properly, is not finding anything. Am I doing something wrong, or is there a better way to do this? Any suggestions for a better approach? Thank you.
UPDATE:I'm actually using a jQuery port called phpQuery for php.
UPDATE2: I don't know the exact class or id of the elements since this is a generic script that I will run on different e-commerce sites, so that's why I'm using the *= wildcard to get all elements (mostly a, div, span, etc, I don't need input). I figured it out and this is what I have so far:
function getPrice($doc){
phpQuery::selectDocument($doc);
$prices = array();
foreach(pq("[class*='Price'], [class*='price'], [id*='Price'], [id*='price']") as $res){
$each = pq($res);
if(preg_match('/\$\d+(?:\.\d+)?/', $each->text(), $matches)){
echo '<br>'.$matches[0].'</br>';
$prices[] = $each->html();
}
}
}
This is printing the correct elements. Now I need to extract the font-size of those elements so I can sort the array by font-size.
Select by ID: $("#Price")
Select by Class: $(".Price")
Showing your HTML would help.