tobz Posted December 5, 2011 Share Posted December 5, 2011 Hi I'm trying to use preg_match to scrape the price of a product from a web site to do a price comparison but, for some reason that I can't work out, it is not returning the expected result. Before you look at this, the URL is an "adult toys" site (not pornographic), so please don't look if that offends you! OK, the URL is http://www.simplypleasure.com/products/novelties-340/chocolate-strawberry-body-pens-40g-each-3896.aspx (don't ask!) My code is as follows: $URL5 = "http://www.simplypleasure.com/products/novelties-340/chocolate-strawberry-body-pens-40g-each-3896.aspx"; $PAGE5 = file_get_contents($URL5); if (preg_match('/<span class=.price.>£(\d+\.\d+)<\/span>/',$PAGE5,$matches)) $PRICE[5] = $matches[1]; else $PRICE[5] = 'na'; I have tested my pattern match via this website http://www.functions-online.com/preg_match.html against the source code of the URL and it correctly returns $matches[1] as 6.00 (need to change £ to £ in that checker to get it to work). I thought perhaps file_get_contents was returning spurious code but I wrote the results to a text file and it seems to be the correct source code. Any ideas welcomed, thanks. Quote Link to comment Share on other sites More sharing options...
xyph Posted December 5, 2011 Share Posted December 5, 2011 This is for personal use? Otherwise it's against their ToS. Quote Link to comment Share on other sites More sharing options...
tobz Posted December 5, 2011 Author Share Posted December 5, 2011 Hello, yes, should have made that clear, when I say for price comparison, it's for my own personal use. I'm trying to make my life easier when comparing prices across sites in the run-up to Xmas. I have similar code working checking prices on other sites but can't figure out what's happening with this particular piece of code/URL. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.