-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.php
46 lines (42 loc) · 1.78 KB
/
scraper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?
// This is a template for a PHP scraper on Morph (https://morph.io)
// including some code snippets below that you should find helpful
require 'scraperwiki.php';
require 'scraperwiki/simple_html_dom.php';
//
// // Read in a page
$html = scraperwiki::scrape("http://www.leboncoin.fr/telephonie/675699535.htm?ca=17_s");
//
// // Find something on the page using css selectors
$dom = new simple_html_dom();
$dom->load($html);
$phoneLink = $dom->find("#phoneNumber a", 0);
if ($phoneLink->href != "") {
$jsonImg = scraperwiki::scrape("http://www2.leboncoin.fr/ajapi/get/phone?list_id=675699535");
var_dump($jsonImg);
if ($jsonImg != '""') {
$i = json_decode($jsonImg);
$src = $i->phoneUrl;
if ($src != "") {
$md5 = md5($src);
if (scraperwiki::select("* from data where 'adId'='675699535'")) {
echo "675699535 already in DB!\n";
} else {
$img = base64_encode(file_get_contents($src));
scraperwiki::save_sqlite(array('adId'), array('md5' => $md5, 'adId' => "675699535", 'content' => $img));
echo "saved 675699535 in DB\n";
}
}
}
}
//
// // Write out to the sqlite database using scraperwiki library
// scraperwiki::save_sqlite(array('name'), array('name' => 'susan', 'occupation' => 'software developer'));
//
// // An arbitrary query against the database
// scraperwiki::select("* from data where 'name'='peter'")
// You don't have to do things with the ScraperWiki library. You can use whatever is installed
// on Morph for PHP (See https://github.com/openaustralia/morph-docker-php) and all that matters
// is that your final data is written to an Sqlite database called data.sqlite in the current working directory which
// has at least a table called data.
?>