-
Notifications
You must be signed in to change notification settings - Fork 1
/
scraper.php
56 lines (45 loc) · 1.3 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
47
48
49
50
51
52
53
54
55
56
<?php
defined('BASEPATH') or exit('No direct script access allowed');
require_once __DIR__ . '/vendor/autoload.php';
use duzun\hQuery;
class Scraper
{
const URL = "http://kamus-sunda.com/sekolah-ikatan-dinas-langsung-kerja.html";
public $type = [
"is" => 2,
"ish" => 3,
"isk" => 4,
"sih" => 1
];
public function get_data($word, $type)
{
$get_html = $this->get_html($word, $type);
$doc = hQuery::fromHTML($get_html);
$pword = $doc->find("div.tkata");
if (!isset($pword))
return false;
$tl = null;
foreach ($pword as $key => $value):
$txt = $value->text();
$w = explode(":", $txt);
$tl = trim($w[1]);
endforeach;
return [
'word' => $word,
'translated' => $tl,
'type' => $this->type[$type]
];
}
private function get_html($word, $type)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::URL);
curl_setopt($ch, CURLOPT_POST, 1);
// form data
curl_setopt($ch, CURLOPT_POSTFIELDS, "text=$word&md=$type");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
return $server_output;
}
}