如何在 instagram 中抓取标签的所有帖子
How to Scrape All posts of hashtag in instagram
我想抓取所有 Post 包含来自 Instagram 的一些#hashtag
我从 :
https://www.instagram.com/explore/tags/perfume/?__a=1
但它只给了一些 post,而不是每个 post。
你可以使用这个库https://github.com/postaddictme/instagram-php-scraper/blob/master/examples/getMediasByTag.php
该函数需要一些媒体作为参数,因此如果您想恢复主题标签的所有媒体,您将必须在 JSON 提要 https://www.instagram.com/explore/tags/perfume/?__a=1
仔细查看您收到的 json。
导航到 graphql -> hashtag -> edge_hashtag_to_media -> page_info -> end_cursor
这是您必须用来指定下一批媒体的标识符,如下所示:
https://www.instagram.com/explore/tags/perfume/?__a=1&max_id=QVFDNWJDZnpGbElpdEV5Q19aaldYWUsxZnc1YUd0Z21yNUZsOWw4V2NxX05ZWnZjT2pRb3lrY29ocDJnM0VNallUWGZVeDIxVURnUzltdHpBR1A1a0VRNw==
您可以重复此过程,为请求的主题标签获取更多媒体。
请求 (python3) 提取前 10 个批次的简单示例。
import requests
import json
from time import sleep
max_id = ''
base_url = "https://www.instagram.com/explore/tags/perfume/?__a=1"
for i in range(0, 10):
sleep(2) # Be polite.
if max_id:
url = base_url + f"&max_id={max_id}"
else:
url = base_url
print(f"Requesting {url}")
response = requests.get(url)
response = json.loads(response.text)
try:
max_id = response['graphql']['hashtag']['edge_hashtag_to_media']['page_info']['end_cursor']
print(f"New cursor is {max_id}")
except KeyError:
print("There's no next page!")
break
正如评论所说,要有礼貌。如果你每秒发送太多请求,Instagram 会屏蔽你。
我想抓取所有 Post 包含来自 Instagram 的一些#hashtag
我从 : https://www.instagram.com/explore/tags/perfume/?__a=1
但它只给了一些 post,而不是每个 post。
你可以使用这个库https://github.com/postaddictme/instagram-php-scraper/blob/master/examples/getMediasByTag.php
该函数需要一些媒体作为参数,因此如果您想恢复主题标签的所有媒体,您将必须在 JSON 提要 https://www.instagram.com/explore/tags/perfume/?__a=1
仔细查看您收到的 json。
导航到 graphql -> hashtag -> edge_hashtag_to_media -> page_info -> end_cursor
这是您必须用来指定下一批媒体的标识符,如下所示:
https://www.instagram.com/explore/tags/perfume/?__a=1&max_id=QVFDNWJDZnpGbElpdEV5Q19aaldYWUsxZnc1YUd0Z21yNUZsOWw4V2NxX05ZWnZjT2pRb3lrY29ocDJnM0VNallUWGZVeDIxVURnUzltdHpBR1A1a0VRNw==
您可以重复此过程,为请求的主题标签获取更多媒体。
请求 (python3) 提取前 10 个批次的简单示例。
import requests
import json
from time import sleep
max_id = ''
base_url = "https://www.instagram.com/explore/tags/perfume/?__a=1"
for i in range(0, 10):
sleep(2) # Be polite.
if max_id:
url = base_url + f"&max_id={max_id}"
else:
url = base_url
print(f"Requesting {url}")
response = requests.get(url)
response = json.loads(response.text)
try:
max_id = response['graphql']['hashtag']['edge_hashtag_to_media']['page_info']['end_cursor']
print(f"New cursor is {max_id}")
except KeyError:
print("There's no next page!")
break
正如评论所说,要有礼貌。如果你每秒发送太多请求,Instagram 会屏蔽你。