响应对象不可下标(尝试获取字典)

时间:2019-03-10 13:04:54

标签: python python-3.x

我正在尝试从instagram上的标签的源代码中获取特定的词典。这就是我所坚持的地方:

Highlighted execution]

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")

0 个答案:

没有答案