aahouzi / Instagram-Scraper-2021

Scrape Instagram content and stories, using a new technique based on the har file (No Token + No public API).
MIT License
111 stars 12 forks source link

A suggestion for automatic photo save #9

Closed yunhwankim2 closed 2 years ago

yunhwankim2 commented 3 years ago

Hi. I have a suggestion for saving photos which already contained in HAR file. The code automatically scroll down to the bottom, so the HAR file already contains photos on the account.

import base64

entries = har["log"]["entries"]
for entry in entries:
    if entry['_resourceType'] == 'image':
        filename = entry["request"]['url'].split('?')[0].split('/')[-1]
        image64 = entry["response"]["content"]["text"]
        with open(filename, "wb") as f:
            f.write(base64.b64decode(image64))

One of the downsides of the above is that it saves all images including post, icons, etc. How about it? Thank you.

yunhwankim2 commented 3 years ago

Of course, below change should be made;

proxy.new_har("new_har", options={'captureHeaders': True, 'captureContent': True, 'captureBinaryContent': True})
ghost commented 3 years ago

Hi Kim! Thank u for ur active contribution to this project, u can create a pull request and I'll test ur code later for merging :)