0

I want to scrap following data( pink color part in image ) from http://www.kitco.com/market/

enter image description here

I was able to scrap data from The World Spot Price - Asia/Europe/NY markets HTML Table below that table using following.. but not able to get the London Fix data.. what changes should i do in the regular expression below as i tried many combinations but it doesnt work

My code looks like the following

$html= get_url_contents("http://www.kitco.com/market/");
//echo $html;


preg_match_all('!Gold\s+([0-9.]+)\s+([0-9.]+)!i',$html,$matches);

$patt = "/<td[^>]*width=['\"]68['\"][^>]*>([0-9\.]+)<\/td>\s*<td[^>]*width=['\"]68['\"][^>]*>([0-9\.]+)<\/td>/i";
user580950
  • 3,558
  • 12
  • 49
  • 94

1 Answers1

0

Please do not parse HTML with regular expressions (you can see why in this mandatory post).

That being said, you can use an HTML parser, such as the Simple HTML DOM Parser to process the table. Take a look at this previous SO post to get started in the right direction.

EDIT: As per your comment, you could try to do something like so: <td bgcolor=".+?">\s*<p>\s*(.+?)\s*</p>\s*</td>. I do however, advise against this approach.

This will match and put the values into regex groups, which you can then, later access.

NOTE: Also as per your comment, the regex you propose is also susceptible style changes, so if they change the width of the columns, your regex will most likely fail.

Community
  • 1
  • 1
npinti
  • 51,780
  • 5
  • 72
  • 96
  • but regex works great for me .. i already parsed the other table using that – user580950 Oct 24 '13 at 05:03
  • 1
    @user580950: I have amended my answer to include a regular expression. However, like I said in my response, this is ***not*** the (right) way to go. – npinti Oct 24 '13 at 05:20