1

I am a complete newbie in python. Trying to scrape the comment from a particular thread in Instagram. I found that everytime I click "load more comments" a requests will be sent and return a json object. Yet the X-Instagram-GIS variable change every-time if I try to sent another new requests for the next query.

I have search online and found that X-Instagram-GIS is a md5 hash variable, created from rhx_gis and the query variable. I have found these two variables but still cannot get the correct value for the next request.

import hashlib

def head_gen(self):
    rhx_gis='4ed1f588adb21e4184a8f6d075782635'
    query_variable='/query/?query_hash=f0986789a5c5d17c2400faebf16efd0d&variables={"shortcode":"Bl3j0I2gF12","first":32,"after":"AQD5RkNkpYakucKwntj2zTK7yvlACbeLfYXraABuucJhckBjlz0ytuaiJMmqnlwo_sjqAbtMa-gdwrZO4-VjEhnTuQbMVnqgnx-Hy8S_5BdA3w"}'
    values = "%s:%s" % (
        rhx_gis,
        query_variable)
    m=hashlib.md5(values.encode())
    print(m.hexdigest())
Eddy Lau
  • 11
  • 2
  • 1
    Use the official Instagram API. –  Aug 07 '18 at 14:05
  • 1
    but i'm really curious how the x-instagram-gis generated – Eddy Lau Aug 07 '18 at 14:10
  • Maybe if you ask Instagram they will tell you. Besides, this is not a Python question, it is a question about reverse engineering some 3rd party application. This boils down to a request for an external resource which is off topic. –  Aug 07 '18 at 14:26
  • no one will say anything to you if you just answer "I don't know how to generate the X-Instagram-GIS header" mate. People are looking for real answer here, not some answer that we all assume to know. – Eddy Lau Aug 07 '18 at 14:39
  • Please read [ask]. –  Aug 07 '18 at 14:45
  • A quick web search yields this discussion, maybe it helps: https://github.com/rarcega/instagram-scraper/issues/205 and https://github.com/rarcega/instagram-scraper/issues/212 –  Aug 07 '18 at 14:46
  • here you go: https://stackoverflow.com/questions/49786980/how-to-perform-unauthenticated-instagram-web-scraping-in-response-to-recent-priv – Igor Nov 28 '18 at 08:34

0 Answers0