max_maggot Posted July 20, 2015 Share Posted July 20, 2015 <div class="price-box"> <span class="regular-price" id="product-price-13129" itemtype="http://schema.org/Offer" itemscope="" itemprop="offers"> <span class="price" itemprop="price">$9.80</span> </span> </div> Hi all, In the above HTML code I am using the following xpath query to try and retrieve the price value ($9.80). I can't seem to get the query correct. Here is what I have come up with so far $items[price] = $xpath->query("//div[@class='price-box']//span/[@class='regular-price']//span/[@class='price']")->item(0)->textContent; //Get and Set price Any help or direction would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/297378-xpath-query-not-returning-value/ Share on other sites More sharing options...
Ch0cu3r Posted July 20, 2015 Share Posted July 20, 2015 Remove the forward slash after span in your xpath $items[price] = $xpath->query("//div[@class='price-box']//span[@class='regular-price']//span[@class='price']")->item(0)->textContent Link to comment https://forums.phpfreaks.com/topic/297378-xpath-query-not-returning-value/#findComment-1516840 Share on other sites More sharing options...
max_maggot Posted July 20, 2015 Author Share Posted July 20, 2015 Figured it out myself. I should have taken 5 more minutes $items[price] = $xpath->query("//div[@class='price-box']/span[@class='regular-price']/span[@class='price']")->item(0)->textContent; Link to comment https://forums.phpfreaks.com/topic/297378-xpath-query-not-returning-value/#findComment-1516841 Share on other sites More sharing options...
max_maggot Posted July 20, 2015 Author Share Posted July 20, 2015 Thanks for your answer Ch0cu3r. I found a xpath query generator and noticed the mistake. http://xmltoolbox.appspot.com/xpath_generator.html Thanks for your help Link to comment https://forums.phpfreaks.com/topic/297378-xpath-query-not-returning-value/#findComment-1516842 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.