我正在尝试从instagram上的标签的源代码中获取特定的词典。这就是我所坚持的地方:
import requests
import json
import pprint as pp
from bs4 import BeautifulSoup
keyword = input("Enter an Hashtag (without#)\n")
url = "https://www.instagram.com/explore/tags/" + keyword + "/?__a=1"
print(url)
def jprint(data_dict):
print(json.dumps(data_dict, indent=4))
def get_ig_page(url):
session = requests.session()
r = session.get(url)
r_code = r.status_code
print(r_code)
if r_code == requests.codes.ok:
return r
else:
return None
ig_data_dict = get_ig_page(url)
if ig_data_dict is not None:
for edge in ig_data_dict["graphql"]["hashtag"]["edge_hashtag_to_top_posts"]:
for e in edge.items():
print(e)
else:
print("oops")