SNS [Instagram][PHP] 인스타그램 해시테그 추출하기
페이지 정보
본문
<div style="text-align:center; padding:0 0 15px 0;">
<div style="float:left; width:50%; text-align:left;"><img src="image/title_instagram.png" style="height:35px;"></div>
<div style="float:left; width:50%; text-align: center; padding:10px 0 0 0px; font-size:1.2em;">#해피정닷컴</div>
<div style="clear:both;"></div>
<?php
function scrape_insta_hash($tag) {
$insta_source = file_get_contents('https://www.instagram.com/explore/tags/'.$tag.'/'); // instagrame tag url
$shards = explode('window._sharedData = ', $insta_source);
$insta_json = explode(';</script>', $shards[1]);
$insta_array = json_decode($insta_json[0], TRUE);
return $insta_array;
}
$tag = '해피정닷컴'; //찾을 태그
$results_array = scrape_insta_hash($tag);
$limit = 12;
$image_array= array();
for ($i=0; $i < $limit; $i++) {
@$latest_array = $results_array['entry_data']['TagPage'][0]['tag']['media']['nodes'][$i];
$image_data = '<a href="https://www.instagram.com/p/'.$latest_array['code'].'/?tagged='.$tag.'" target="_blank"><img src="'.$latest_array['thumbnail_src'].'" style="width:25%; margin:0px;"></a>';
//$image_data = '<img src="'.$latest_array['display_src'].'">';
array_push($image_array, $image_data);
}
foreach ($image_array as $image) {
echo $image;
}
// for getting all images have to loop function for more pages
// for confirmation you are getting correct images view
// https://www.instagram.com/explore/tags/your-tag-name/
?>
</div>
참고자료
https://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=qna_function&wr_id=446189
<div style="float:left; width:50%; text-align:left;"><img src="image/title_instagram.png" style="height:35px;"></div>
<div style="float:left; width:50%; text-align: center; padding:10px 0 0 0px; font-size:1.2em;">#해피정닷컴</div>
<div style="clear:both;"></div>
<?php
function scrape_insta_hash($tag) {
$insta_source = file_get_contents('https://www.instagram.com/explore/tags/'.$tag.'/'); // instagrame tag url
$shards = explode('window._sharedData = ', $insta_source);
$insta_json = explode(';</script>', $shards[1]);
$insta_array = json_decode($insta_json[0], TRUE);
return $insta_array;
}
$tag = '해피정닷컴'; //찾을 태그
$results_array = scrape_insta_hash($tag);
$limit = 12;
$image_array= array();
for ($i=0; $i < $limit; $i++) {
@$latest_array = $results_array['entry_data']['TagPage'][0]['tag']['media']['nodes'][$i];
$image_data = '<a href="https://www.instagram.com/p/'.$latest_array['code'].'/?tagged='.$tag.'" target="_blank"><img src="'.$latest_array['thumbnail_src'].'" style="width:25%; margin:0px;"></a>';
//$image_data = '<img src="'.$latest_array['display_src'].'">';
array_push($image_array, $image_data);
}
foreach ($image_array as $image) {
echo $image;
}
// for getting all images have to loop function for more pages
// for confirmation you are getting correct images view
// https://www.instagram.com/explore/tags/your-tag-name/
?>
</div>
참고자료
https://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=qna_function&wr_id=446189