U
U
user-agent2020-04-30 10:14:59
Python
user-agent, 2020-04-30 10:14:59

Parser returns html instead of json?

Wrote an instagram parser to get the id and username of a user from a link.
Here is the code:

href = 'https://instagram.com/instagram/'
response = requests.get(href + '?__a=1')
user = json.loads(response.text) #получаем json, в котором указан id и username
user_id = user['graphql']['user']['id'] #получаем id 
username = user['graphql']['user']['username'] #получаем username
print(user_id, username) #выводим id и username

The script works in the Django site view when an ajax request is sent. Everything works fine on the locale - I get json and work further, and on a flooded site it gives out html. I decided to render the html and saw that it renders the instagram login page instead of the user page. What could be causing this error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-04-30
@user-agent

With the fact that Instagram blocks parsers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question