Page 1 of 1
How to Collect data from websites
Posted: Sun Feb 12, 2012 11:13 pm
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
Re: How to Collect data from websites
Posted: Sun Feb 12, 2012 11:59 pm
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.
Re: How to Collect data from websites
Posted: Mon Feb 13, 2012 1:41 am
by phpjawahar
Thanks for your help.
Could you give me any tutorial site to learn more on this.
With Regards,
Jawahar
Re: How to Collect data from websites
Posted: Mon Feb 13, 2012 6:16 am
by Celauran