How to extract a table row from a web page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
atyler
Forum Newbie
Posts: 17
Joined: Tue May 26, 2009 10:28 pm

How to extract a table row from a web page

Post 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
Gargoyle
Forum Contributor
Posts: 130
Joined: Wed Jul 14, 2010 12:25 am

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

Post 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.
Post Reply