-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape.php
More file actions
134 lines (109 loc) · 3.41 KB
/
Copy pathscrape.php
File metadata and controls
134 lines (109 loc) · 3.41 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* Created by PhpStorm.
* User: ITACHI
* Date: 11/11/2018
* Time: 2:41 PM
*/
$curl = curl_init();
$url = "http:/www.imdb.com/search/title"
."?year=2000,2000&title=feature&sort=moviemeter,asc&page=76&ref=adv_nxt";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
$movies = array();
//match movie title
preg_match_all('<a href="\/title\/.*?\/?ref_=adv_li_tt">(.*?)<\/a>', $result,$match);
$movies['name'] = $match[1];
//match movie year
preg_match_all('<span class="lister-item-year text-muted unbold">\(.*(\d{4}) \w*?\)<\/span>', $result,$match);
$movies['year'] = $match[1];
//match image url
preg_match_all('', $result,$match);
$movies['image'] = $match[1];
//match certificate, runtime, genre block
preg_match_all('', $result,$match);
//match certificate, runtime, genre block individually from above block
for($i=0;$i<count($match[1]); $i++){
//match certificate
if(preg_match('', $match[1][$i], $certificate)){
$movies['certificate'][$i] = $certificate[1];
}else{
$movies['certificate'][$i] = '';
}
//match runtume
if(preg_match('', $match[1][$i], $runtime)){
$movies['runtime'][$i] = $runtime[1];
}else{
$movies['runtime'][$i] = '';
}
//match genre
if(preg_match('', $match[1][$i], $genre)){
$movies['genre'][$i] = $genre[1];
}else{
$movies['genre'][$i] = '';
}
}
//match rating bar block
preg_match_all('', $result,$match);
//match rating individually
for($i=0;$i<count($match[1]); $i++){
//match certificate
if(preg_match('', $match[1][$i], $imdb_rating)){
$movies['imdb_rating'][$i] = $imdb_rating[1];
}else{
$movies['imdb_rating'][$i] = '';
}
}
//match the metascores and description together, make metascore optional
preg_match_all('', $result,$match);
for($i=0;$i<count($match[0]); $i++){
//match certificate
if(preg_match('', $match[0][$i], $metascore)){
$movies['metascore'][$i] = $metascore[1];
}else{
$movies['metascore'][$i] = '';
}
if(preg_match('', $match[0][$i], $description)){
$movies['description'][$i] = $description[1];
}else{
$movies['description'][$i] = '';
}
}
//match directors and stars block
preg_match_all('', $result,$match);
for($i=0;$i<count($match[1]); $i++){
//match certificate
if(preg_match('', $match[1][$i], $directors)){
//print_r($directors);die;
$clean_directors = preg_replace('','', $directors);
$movies['directors'][$i] = $clean_directors;
}else{
$movies['directors'][$i] = '';
}
if(preg_match('', $match[0][$i], $stars)){
preg_match_all('', $stars[1], $all_stars);
$movies['stars'][$i] = implode(', ',$all_stars[1]);
}else{
$movies['stars'][$i] = '';
}
}
//match votes block, votes and gross, (because Gross can be empty)
//votes pr gross can be empty, they can also both be empth. make them both optional
$regex = '';
//<div class="lister-item mode-advanced">
preg_match_all($regex, $result, $match);
for($i=0;$i<count($match[0]); $i++){
//match certificate
if(preg_match('', $match[0][$i], $votes)){
$movies['votes'][$i] = $votes[1];
}else{
$movies['votes'][$i] = '';
}
if(preg_match('', $match[0][$i], $gross)){
$movies['gross'][$i] = $gross[1];
}else{
$movies['gross'][$i] = '';
}
}
print_r($movies);