Last active
December 20, 2020 14:04
-
-
Save kevincobain2000/f204bdac97939fb38725500579ee56f4 to your computer and use it in GitHub Desktop.
Pinterest Search From Tags, Unofficial Scrape PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function searchPinterest($q) | |
{ | |
$url = "https://jp.pinterest.com/search/pins/?q=$q"; | |
$html = file_get_contents($url); | |
$domd = new \DOMDocument(); | |
libxml_use_internal_errors(true); | |
$domd->loadHTML($html); | |
libxml_use_internal_errors(false); | |
$items = $domd->getElementsByTagName('script'); | |
$data = array(); | |
foreach ($items as $item) { | |
$data[] = [ | |
'src' => $item->getAttribute('src'), | |
'outerHTML' => $domd->saveHTML($item), | |
'innerHTML' => $domd->saveHTML($item->firstChild), | |
]; | |
} | |
foreach ($data as $key => $value) { | |
$response = json_decode($value['innerHTML']); | |
if (!$response) { | |
continue; | |
} | |
if (isset($response->tree->data->results)) { | |
foreach ($response->tree->data->results as $obj) { | |
print_r($obj->like_count); | |
$images = (Array) $obj->images; | |
print_r($images['736x']->url); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment