Hi I’m trying to extract the locations of jobs from a website so that I can have them overlaid on to google maps. I have the scraper working successfully, but it only seems to grab the first location. I have minimal PHP knowledge, but I have experience with other languages so I’m not new to coding.
This is the small PHP scraper that I wrote:
[php]<?PHP
$scraped_page = file_get_contents(“http://huntersandgatherers.jobamatic.com/a/jobs/find-jobs/l-07410/sb-pd/pn-1”);
//scraping location
$regex_location= ‘/<td class=“location”>(.+?)</td>/’;
preg_match($regex_location,$scraped_page,$scraped_location_data);
var_dump($scraped_location_data);
echo “$scraped_location_data[1]”;
?>[/php]
When it executes var_dump($scraped_location_data) it outputs array(2) { [0]=> string(38) "New York, NY" [1]=> string(12) "New York, NY" }
so it’s obviously working. I see that there’s two slots in the array that both contain “New York, NY” even though it only exists once on the page.
How can I get it to store the 25 locations on the first page into an array that can easily be iterated through later?