I deleted my Facebook on June 10th 2016, and upon this event—now that I sense the irony of it—I decided to tweet about it. I jumped from one network to the other, without really realizing that both profit off of selling my behavioral data regardless. Even Twitter makes money off of ads and behavioral data, but nothing comes close to Facebook. Even Google does not come close to what Facebook knows about certain aspects of its users, and how it has the capability to manipulate them psychologically.1 In her book Weapons of Math Destruction, Cathy O’Neil talks much about these systems.

Now that Facebook owns Instagram and WhatsApp, I have continued my move away from these services. Summer is the perfect time for me to do these moves, since I no longer rely on communications as much as I do during other times of the year. As of now, I have no Facebook-owned apps installed on my phone, because I feel no urge to sell my data in exchange for a manipulative service. Especially since there are plenty of other alternatives.

The Fix

But I have to say, it is hard to be without Instagram because I no longer see what my friends are up to. Maybe this is a good thing. But it would still be nice to have the ability to have access to the feeds of my friends without being exploited by Facebook.

Getting the Username List

So first thing we have to do is get a list of usernames that we follow. There are plenty ways of doing this. Assuming that you don’t follow more 10000’s of accounts, the best way is to go to the web version of Instagram and click on the Following button to get a list of those who you follow.

image1
Here we have a list of users that we follow.

Now we want to inspect each HTML element and find out the name of its HTML class. On Mac, we can press Command+Option+I to bring up the HTML inspector.

image2

By bringing the inspector, we can find out the HTML class name of each username element.

Now that we have the name of the HTML class which represents the usernames that we want, we need to output all the usernames into a list. In this particular example, the HTML class called _4zhc5 is the one that represents the username text that we need to output into a list.

First, we have to paste a script that would allow us to save our username list to a text file. Here is a script, just paste it into your web console. It should work on most browsers.2

(function(console){
    console.save = function(data, filename){

      var blob = new Blob([data], {type: 'text/plain'}),
      e    = document.createEvent('MouseEvents'),
      a    = document.createElement('a')

      a.download = filename
      a.href = window.URL.createObjectURL(blob)
      a.dataset.downloadurl =  ['text', a.download, a.href].join(':')
      e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
      a.dispatchEvent(e)
    }
  })(console)

image3
Like so, then press Enter.

Now we can paste the main script which will download a text file to our Downloads folder. Remember to substitute _4zhc5 with whatever HTML class name that represents usernames.

var list = document.getElementsByClassName("_4zhc5"),
text = "";
// loop through the list array containing the usernames
for (i in list) {
  // keep adding to the text with a line break at the end
  text += list[i].innerText + " \n"
}
// download the file
console.save(text,"insta-following-list.txt")

Copy and paste this script into the console just like the previous one.

image4

Once we do that, we should get a file with a list of usernames downloaded by our browser called insta-following-list.txt which will be formatted like so:

user1
user2
user3

# and so on...

This is quite nice since we can now use this list to scrape the Instagram accounts of these listed usernames.

Scraping Instagram

Now that we have a list of usernames that we want to scrape, we can use a script called instagram-scraper. Open a new window terminal and download the script and type in the following (ignore the $ sign):

$ pip install instagram-scraper

Now create a folder in your home directory to where we will scrape our Instagram content:

$ mkdir ~/my-instagram
$ instagram-scraper -n -d ~/my-instagram -f path/to/insta-following-list.txt -l -u your-username -p your-password

Script Explanation

  • Option -n tells the instagram-scraper command to create folders for each username instead of dumping all images into my-instagram folder.
  • Option -d specifies the destination to which we want to scrape our content. In this case it is ~/my-instagram where the ~/ specifies that it is located in your home directory.
  • Option -f specifies the file path to our insta-following-list.txt. Find the path to this file, an paste it. On Mac, it should be ~/Downloads/insta-following-list.txt.
  • The option -l signifies not to start script unless your login is successfully authenticated. This command is only necessary if you want to scrape private accounts. If you want to scrape only public accounts, use the command without -l and everything after it.
    • Option -uspecifies your Instagram username. Paste this without any quotes by replacing your-username.
    • Option -pspecifies your Instagram password. Paste this without any quotes by replacing your-password.

Note: There might be some problems with the script while it attempts to login into your Instagram account. Try resting your Instagram password and retry the command with the new password. This usually solves the problem.

Result

Once you run the script successfully, you should get a folder structure similar to this one:

/my-instagram
  username1/
  username2/
  username3/
  .../

Now you have the Instagram content of all your usernames on your hard drive.

Now that we scraped all these images, what is the point if they are just stored on our computer? We can create a Browsable web-gallery using a script called gallery_shell.

Open a new terminal window and type the following:

Cd to your home directory:

$ cd ~/

Download the script:

$ git clone https://github.com/Cyclenerd/gallery_shell

Make the script executable:

$ chmod +x gallery_shell/gallery.sh

Now cd to the folder containing all the scraped usernames:

$ cd my-instagram/

Now this script will go throughout all the username folders located in my-instagram/ folder and create a browsable html page with thumbnails for each username folder:

for d in ~/my-instagram/*/; do (cd "$d" && ~/gallery_shell/gallery.sh); done

Done! Now we need to serve the web content using python:

$ python -m SimpleHTTPServer 8000

Now type localhost:8000 into your web browser and you should see a list of Instagram usernames:

image5

Once you click on ant of these links, you’ll see a thumbnail gallery for each username, including private accounts if you chose to include your Instagram credentials.

image6

Conclusion

This is not exactly a copy of Instagram and looks more like a hack, but it is a very great way to continue using Instagram without being subservient to the systems owned by Facebook. Plus, you will be able to backup Instagram Stories which disappear from Instagram after 24 hours.

For the next blog, We’ll be looking at how to setup an Instagram backing up process.

  1. This is not to state that Facebook takes advantage of this capability. In fact, even if it does, it would be hard for anyone outside of Facebook to prove it due to the nature of these hidden algorithms. However there is an abundance of evidence that Facebook does alter the feeds of its users. 

  2. Script source link