-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.php
51 lines (42 loc) · 1.25 KB
/
temp.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
// loop through the data
$nodeValues = $crawler->filter('.board-text > a')->each(function (Crawler $node, $i) {
$category = $node->filter
return [
'category' => $node->filter('.category')->text(),
'text' => $node->text(),
'link' => 'https://www.kw.ac.kr'.$node->attr('href')
];
//return $node->text();
});
print_r($nodeValues);
------------------------------------------
<?php
require 'vendor/autoload.php';
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\CssSelector\CssSelectorConverter;
$url = 'https://www.kw.ac.kr/ko/life/notice.jsp';
$client = new GuzzleHttp\Client();
$res = $client->request('GET', $url);
// echo $res->getStatusCode(); // 200
// echo $res->getHeader('content-type')[0];
$html = ''.$res->getBody();
// get the data from $url
$crawler = new Crawler($html);
$crawler = $crawler
->filter('.board-text > a')
->reduce(function (Crawler $node, $i) {
// bring up to 12 notice
return ($i < 12);
});
$category = $crawler->each(function (Crawler $node, $i) {
return $node
->filter('.category')
->text("");
});
$title = $crawler->each(function (Crawler $node, $i) {
$tmpString = $node->text();
$tmpString = substr($tmpString, strlen($category[$i]));
return $tmpString;
//return $node->text();
});
print_r($title);