python requests使用登陆之后的cookie

    def getcontent(self):
       cookie_text=r'ur=FTW; mid=WsrlLwAEAAEfpCstNyTJl-1oZa0w; ig_pr=1; ig_vh=949; csrftoken=aaaaaaa;ig_vw=186'#字符串格式
       cookies = {}
       for cookie_unit_text in cookie_text.split('; '):
            cookie_unit = cookie_unit_text.split('=')
            if len(cookie_unit) >= 2:
                cookies[cookie_unit[0]] = cookie_unit[1]
       req=requests.session()
       req.proxies.update(self.proxies)
       for k,v in cookies.items():
           req.cookies.set(k, v)  # 转换cookies
       param1 = quote_plus(r'33ba35852cb50da46f5b5e889df7d159')
       param2=quote_plus(r'{"shortcode":"BhRQ25qHnNI","first":1220}')
       geturl=r"https://www.instagram.com/graphql/query/?query_hash={}&variables={}".format(param1,param2)
       print(geturl)
       reqs= req.get(geturl,headers=self.headers)
       jsonstr=reqs.json()
       pprint.pprint(jsonstr)

  

posted @ 2018-04-09 14:46  公众号python学习开发  阅读(529)  评论(0编辑  收藏  举报