How to Collect data from websites

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
phpjawahar
Forum Newbie
Posts: 19
Joined: Thu Jan 12, 2012 6:06 am
Location: Chennai, India

How to Collect data from websites

Post by phpjawahar »

I want to collect information from web pages.

Currently I copy and paste the information or address details in to excel then i export it to the database from the web pages.

Could i do this using php. If so how?

With Regards,
Jawahar
G l a z z
Forum Newbie
Posts: 24
Joined: Sun Feb 12, 2012 10:33 pm

Re: How to Collect data from websites

Post by G l a z z »

Hi,

Yes you can get data from another web site.

You can achieve this using cURL or file_get_contents.


cURL Example:

Code: Select all

$url = 'http://your-website-to-crawl-data.com;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec ($ch);
curl_close ($ch);
// you can do something with $data like explode(); or a preg match regex to get the exact information you need
echo $data;

file_get_contents Example:

Code: Select all

$text = file_get_contents('http://your-website-to-crawl-data.com/') ;
preg_match ("/<!--start product-->([^`]*?)<!--end product-->/", $text, $temp); // get data out of the page
echo htmlentities($temp[0]) ; // splits out the 1st occurance of your data

Something like this.
phpjawahar
Forum Newbie
Posts: 19
Joined: Thu Jan 12, 2012 6:06 am
Location: Chennai, India

Re: How to Collect data from websites

Post by phpjawahar »

Thanks for your help.

Could you give me any tutorial site to learn more on this.

With Regards,
Jawahar
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How to Collect data from websites

Post by Celauran »

Post Reply