-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
56 lines (35 loc) · 1023 Bytes
/
index.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
use DiDom\Document;
require "./vendor/autoload.php";
$document= new Document("https://www.uonbi.ac.ke/research-news", true);
function getAllTitles($document){
$data= "";
$content = $document->find('#content')[0];
$containerArray = $content->find('.field-content');
$posts= ($content ->find('.views-field-title'));//this should return an aray
for($i=0; $i<count($containerArray); $i++){
// $img =$containerArray[$i]->find('.views-field-field-thumbnail::attr(href)')[0];
echo "<strong> Title: </strong>" .$posts[$i]->text();
echo "<br>";
// echo $img;
echo"<br><br>";
$data = $data.
"<strong> Title: </strong>" .$posts[$i]->text();
"<br>";
// echo $img;
"<br><br>";
}
saveData($data);
}
getAllTitles($document);
function saveData($data) {
if(!is_dir("Research")){
mkdir("Research");
}
//create file
$file = fopen('Research/data.txt','w');
fwrite($file,$data);
fwrite($file, "\n\n");
fclose($file);
}
?>