-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.php
65 lines (52 loc) · 1.66 KB
/
parse.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
<?php
$file = "file.csv";
// $url = "http://www.stackoverflow.com/";
//parsing csv file
$expected = array_map('str_getcsv', file('file.csv'));
$url = $expected[1][0];
function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIE, "test=seo");//for cookie
$data = curl_exec($ch);
curl_close($ch);
return $data;
};
$html = file_get_contents_curl($url);
//parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
//get and display what you need:
$title = $nodes->item(0)->nodeValue;
$metas = $doc->getElementsByTagName('meta');
$description = "";
for ($i = 0; $i < $metas->length; $i++)
{
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'description')
$description = $meta->getAttribute('content');
}
// system('clear');
echo "URL: $url\r\n";
echo "Title: $title\r\n";
echo "Description: $description \r\n\r\n";
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 0);
assert_options(ASSERT_QUIET_EVAL, 1);
assert_options(ASSERT_CALLBACK, 'my_assert_handler');
function my_assert_handler($file, $line, $code, $desc = null)
{
echo " ! Assertion failed: ";
if ($desc) {
echo "$desc";
}
echo "\n";
}
assert ($expected[1][1]==$title,"Expected ".$expected[0][1]." is: '".$expected[1][1]."' and actual is: '" . $title."'.\r\n");
assert ($expected[1][2]==$description,"Expected ".$expected[0][2]." is: '".$expected[1][2]."' and actual is: '".$description."'.\r\n");
?>