forked from gramener/pinterest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
getboards.php
75 lines (64 loc) · 1.49 KB
/
getboards.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
73
74
75
<?php
/*
* author: Jayaseelan Gabriel
* Run: getboards.php?userid=ID
*
*/
require_once 'simple_html_dom.php';
// new code
function getTextBetweenTags($string) {
//"totalPages": 7
$pattern = "/totalPages\": (\d)/";
preg_match($pattern, $string, $matches);
if(count($matches)>0){
return str_replace('"',"",$matches[0]);
}
return '';
}
// End
// Trim user ID
$userid= trim($_GET['userid']);
$url = "http://pinterest.com/$userid/";
// Code for get all boards
$html = file_get_html($url);
$totalnumberofpage='';
foreach($html->find('script') as $e){
$x=getTextBetweenTags($e);
if($x!=''){
$totalnumberofpage=$x;
}
}
if($totalnumberofpage!=''){
$arr=explode(":",$totalnumberofpage);
$totalPages= trim($arr[1]);
}else{
$totalPages=1;
}
// End new code
$rs = array();
for($i=1;$i<=$totalPages;$i++){
$url = "http://pinterest.com/$userid/?page=".$i;
$html = file_get_html($url);
foreach($html->find('div[class=pinBoard]') as $pin){
foreach($pin->find('h3') as $boardname){
if($pin->find('span[class=cover] img',0)==null){
$rs[] = array(
$boardname->plaintext,
$boardname->find('a', 0)->href,
'#',
$pin->find('h4', 0)->plaintext
);
}else{
$rs[] = array(
$boardname->plaintext,
$boardname->find('a', 0)->href,
$pin->find('span[class=cover] img',0)->src,
$pin->find('h4', 0)->plaintext
);
}
}
}
}
header('Content-type: application/json');
echo json_encode($rs);
?>