-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpinterest.php
112 lines (99 loc) · 3.54 KB
/
pinterest.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
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
<?php
/**
* Projet Korleon - Pinterest
*
* @description : Scrappe les 150 dernières images d'une recherche pinterest
* @author julien.anquetil
* @version 1.3
*/
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Scraper Pinterest</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<style type="text/css">
img {max-height:200px;}
</style>
</head>
<body>
<div class="container">
<h1>Rechercher des images a scrapper sur Pinterest</h1>
<form>
<div class="form-group">
<label for="search">Mot a rechercher</label>
<div class="input-group">
<input type="text" name="search" class="form-control" id="search" placeholder="Recherche">
<div class="input-group-addon"><i class="glyphicon glyphicon-search"></i></div>
</div>
<button type="submit" class="btn btn-default">Rechercher</button>
</form>
<?php
/**
* Configuration
*/
//Parametres du proxy
$ProxyIp = '';
$ProxyLogin = '';
$ProxyPassword = '';
if (!file_exists('img/')) {
mkdir('img/', 0777, true);
}
fopen("img/content.html", "w");
function ImageName($filePath) {
$fileParts = pathinfo($filePath);
if (!isset($fileParts['filename'])) {
$fileParts['filename'] = substr($fileParts['basename'], 0, strrpos($fileParts['basename'], '.'));
}
return $fileParts['basename'];
}
if (isset($_GET["search"])) {
$search = urlencode($_GET["search"]);
$url = "https://www.pinterest.com/search/boards/?q=" . $search;
//Creation de l'authentification
if ($ProxyIp != '') {
$auth = base64_encode($ProxyLogin . ':' . $ProxyPassword);
$Context = array(
'http' => array(
'proxy' => 'tcp://' . $ProxyIp,
'request_fulluri' => true,
'header' => "Proxy-Authorization: Basic $auth",
),
);
$cxContext = stream_context_create($Context);
$doc = file_get_contents($url, False, $cxContext);
file_put_contents('img/content.html',$doc);
} else {
$doc = file_get_contents($url);
file_put_contents('img/content.html',$doc);
}
$domdocument = new DOMDocument();
libxml_use_internal_errors(true);
$domdocument->loadHTMLFile('img/content.html');
$a = new DOMXPath($domdocument);
$imgs = $a->query('//img[contains(@class,"thumb")]');
echo '<h2>Résultat de la recherche : <span class="text-success">'.$search.'</span></h2>';
echo '<div class="row row-eq-height">';
foreach ($imgs as $img) {
$url_image = $img->getAttribute('src');
$image_name = ImageName($url_image);
$url_big = str_replace('pinimg.com/75x75/', 'pinimg.com/736x/', $url_image);
if (!file_exists("img/" . $image_name)) {
copy($url_big, "img/".$image_name);
echo ' <div class="col-md-2"><img src="' . $url_image . '" class="img-responsive"/><p class="text-info text-center "> Récupérée</p></div>' . PHP_EOL;
} else {
echo '<div class="col-md-2"><img src="' . $url_image . '" class="img-responsive"/><p class="text-danger text-center "> Existe deja</p></div>' . PHP_EOL;
}
}
echo '</div>';
}
?>
</div>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>