Skip to content

Instantly share code, notes, and snippets.

@kevincobain2000
Last active December 20, 2020 14:04
Show Gist options
  • Save kevincobain2000/f204bdac97939fb38725500579ee56f4 to your computer and use it in GitHub Desktop.
Save kevincobain2000/f204bdac97939fb38725500579ee56f4 to your computer and use it in GitHub Desktop.
Pinterest Search From Tags, Unofficial Scrape PHP
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