-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
70 lines (70 loc) · 2.43 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
<!-- Name: Venkatesh
Created:2/12/2016
Description: This is the index page for the webpage Parser application. User first lands here and he/she enters an URL or selects the existing
URLfrom the given list. The list of articles in this page are generated by parsing the "http://cnn.com/world/" page. The list will be updated by time
as it directly loads from the CNN website -->
<!-- Start of PHP code -->
<?php
//It is adivisable to set time limit atleast 60 seconds as some articles may loads slow
set_time_limit(60);
//MyParser class contains all the required parsing functions which needs to be included first
include('MyParser.php');
//The following statement creates an object by calling the MyParser constructor with CNN page
$myobj=new MyParser("http://www.cnn.com/world/");
//Once the object is loaded, getArticles() function parses the intital page of CNN and extracts artciiles from the other links
$articles=$myobj->getArticles($myobj->getLinks());
?>
<!-- HTML code starts from here -->
<html>
<head>
<title> Webpage Parser</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
</head>
<body>
<center>
<h2>
PHP - Webpage Parser
</h2>
</center>
<!-- User may copy/paste a CNN article in the text field or may select article from the given list -->
<form method="post" action="result.php">
<div class="container">
<h2>Enter URL</h2>
<p>Enter an URL in the below textfield</p>
<form role="form">
<div class="form-group">
<input type="text" class="form-control" name="url" >
</div>
</form>
</div>
</form>
<div class="container">
<h2>Select an URL</h2>
<p>Enter an URL in the above textfield or simply select an URL from the below</p>
<!-- The following articles are loaded directly from the CNN website (Live) -->
<table class="table table-striped">
<thead>
<tr>
<th>Latest articles from CNN (Live)</th>
</tr>
</thead>
<tbody>
<?php
// This loop iterates through the CNN articles array
foreach($articles as $article)
{
echo '<tr>
<td>
<a href="result.php?url='.$article.'" target="_blank">'.$article.'</a>
</td>
</tr>
';
}
?>
</tbody>
</table>
</div>
</body>
</html>