I'm trying a web scraping with my virtual web server; I'm looking for the name of projects + the name of creator in the page for example Bring THE PEOPLE TO COME to New York City by Yanira Castro
These information are locaded in bbcard_name
My problem is that the array and csv i receive at the end of the script always are empty...
<?php
set_time_limit(0);
$data = array ()
$listpage = file_get_contents('http://www.kickstarter.com/discover/categories/dance/');
preg_match_all('#<h2> <a href="([A-Z]+)\.html">([a-za-Z ]+)</a></li>#', $listpage, $pagesurl);
foreach($pageurl[1] AS $pagesurl) {
$projectPage = file_get_contents('http://www.kickstarter.com/discover/categories/dance/' . $pagesurl . '.html');
preg_match('#<h2>bbcard_name ([a-zA-Z ]+)</h2>#', $projectPage, $name);
$name = $name[1];
preg_match_all('#<h2><a href="https?://.+\.[a-z]{2,5}">([^<]+)</a>#', $projectPage, $namefound);
foreach($namefound[1] AS $name) {
if(!isset($data[$name]))
$data[$name] = array('name' => $name);
else
$data[$name]['name'] .= ' - ' . $name;
}
}
print_r($data);
$out = fopen('data.csv', 'w');
fputcsv($out, array('Titre'));
foreach ($data as $name => $data) {
$name = (isset($data['name'])) ? $data['name'] : '';
fputcsv($out, array($data,$name));
}
fclose($out);
echo "FINITO";
exit;
?>
Thanks