Page 1 of 1

How to extract a table row from a web page

Posted: Thu Jul 22, 2010 4:53 pm
by atyler
I'd guess this has been asked/answered before, but I couldn't find anything, so...

I want to read a web page into my PHP script, and then in that script be able to "query" the page to pull a specific row from a specific table.

For example, I'd like to read this row's elements into an array:
12.500 .WIN\10K20\12.5 0.150 +0.02 +15.38% 0.160 0.120 0.160 19 5,363

and the original table can be found here: http://moneycentral.msn.com/investor/op ... &Year=2010

Any suggestions on the best way to do this?

I've looked at the snoopy class, but haven't been able to get it to work. I could be doing something wrong with the class, or it maybe just isn't the right tool for the job. ?? http://sourceforge.net/projects/snoopy/

The key here is I want to be able to "query" the page to find a specific row.

Thanks for any constructive input!
AT

Re: How to extract a table row from a web page

Posted: Fri Jul 23, 2010 12:42 am
by Gargoyle
well, go to that site, visually scan through the source to find the row in question, then port the logic you used to php code.

there is no general magick "extra the text I want" function in PHP (or any other programming language, you will get close with LISP though), so you will have to do it yourself. functions that will come in handy are strpos(), substring(), explode() and preg_match().

your main problem is that human logic has to be ported to something the machine understands, which can be extremely difficult and sometimes nearly impossible.