This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
72 lines (58 loc) · 1.79 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
require_once('simple_html_dom.php');
require './vendor/autoload.php';
?>
<html>
<head>
<title>Web Crawler | Fadhil Amadan | 160414063</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<form class="form-wrapper" action="" method="POST">
<center>
<h1>Web Crawler</h1>
<h4>Fadhil Amadan | 160414063</h4>
</center>
<input type="text" name="keyword" id="search" placeholder="Search for..." required>
<input type="submit" value="go" id="submit" name="submit">
</form>
<?php
if(isset($_POST["keyword"])) {
//Load URL
$html = file_get_html('https://twitter.com/search?f=tweets&vertical=news&q='.$_POST["keyword"]);
//Array
$daftar_tweet=[];
//Cari 5 Tweet Teratas
$i = 0;
foreach ($html->find('div[class="content"]') as $tweet) {
if ($i > 5) break;
else {
$userTweet = $tweet->find('span[class="username u-dir"]',0)->innertext;
$textTweet = $tweet->find('p[class="TweetTextSize js-tweet-text tweet-text"]',0)->innertext;
/*START - Stemmer and Stop Word*/
$stemmerFactory = new \Sastrawi\Stemmer\StemmerFactory();
$stemmer = $stemmerFactory->createStemmer();
$stopwordFactory = new \Sastrawi\StopWordRemover\StopWordRemoverFactory();
$stopword = $stopwordFactory->createStopWordRemover();
$sentence = $textTweet;
$output = $stemmer->stem($sentence);
$output2 = $stopword->remove($output);
/*END - Stemmer and Stop Word */
$daftar_tweet[] = [
'<strong>User</strong>' => $userTweet,
'<strong>Tweet Asli</strong>' => $textTweet,
'<strong>Tweet Stem</strong>' => $output2];
}
$i++;
}
//Print
foreach ($daftar_tweet as $key => $item) {
foreach ($item as $index => $content) {
echo $index . " : " . $content . "<br>";
}
echo "<br><br>";
}
}
?>
</body>
</html>