How to get Instagram image details

耗尽温柔 提交于 2020-01-23 13:19:05

问题


I am working on an app to get images details from Instagram by using selenium with python.

driver.execute_script(SCROLL_TOP)
driver.execute_script(SCROLL_BOTTOM)

In the result, all posted images and captions can be gotten from driver.page_source

But when I trying to get more information about an image (e.g, number of likes, date of the image published). I need to access

<script type="text/javascript">window._sharedData = {...}</script>

The '...' in the previous code is a JSON block. It contains the first 12 media's details. Is there a way I get all image's details in the window._shareData JSON block?

Thanks for your advice


回答1:


Take a look at my answer which solves your problem but with php. Anyway, you can do the same with python:

  1. Load the json by http from the url: https://www.instagram.com/nasa/?__a=1 (replace nasa with any public username).

  2. Get 12 media details from the json: user->media->nodes.

  3. Get the additional media info from the json: user->media->page_info. There are has_next_page (boolean) and end_cursor (integer). Use it to get next 12 media with url https://www.instagram.com/nasa/?__a=1&max_id=[VALUE-FROM-end_cursor].

  4. Repeat 2-3.


来源:https://stackoverflow.com/questions/40877566/how-to-get-instagram-image-details

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!