Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/252528-preg_match-problem/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/252528-preg_match-problem/#findComment-1294718
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.