Extract data from external website using PHP

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
nixes
Forum Newbie
Posts: 4
Joined: Wed Apr 07, 2010 8:33 am

Extract data from external website using PHP

Post by nixes »

Hi all,

I'm looking to find a way to extract data from a table in an external website and store it in an SQL database. Can this be achieved using standard html/php/SQL or will I be required to code this as a seperate tool that runs locally alongside the website?

Any help/advice from people with experience in this field would be greatly appreciated!

Many thanks,
Nick
minorDemocritus
Forum Commoner
Posts: 96
Joined: Thu Apr 01, 2010 7:28 pm
Location: Chicagoland, IL, USA

Re: Extract data from external website using PHP

Post by minorDemocritus »

The first thing that comes to mind is cURL. You'd have to find another library that allows you to pull table data out of the markup, though.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Extract data from external website using PHP

Post by Jonah Bron »

Just use the DOM to parse the HTML with DOMDocument::loadHTML. Then you can extract the table.
nixes
Forum Newbie
Posts: 4
Joined: Wed Apr 07, 2010 8:33 am

Re: Extract data from external website using PHP

Post by nixes »

Hey,

Thanks very much for the suggestions. I'm not massively familiar with DOMDocument and loadHTML. I've done a bit of research and looked in the php manual but still not sure I get it. Could anyone give me a quick description of how it should work in this instance?

Many thanks,
Nick
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Extract data from external website using PHP

Post by omniuni »

Well, you could always try file_get_contents($url);
Post Reply