Jean-Charles Evrard
Jean-Charles Evrard

Reputation: 1

Scrape Instagram's usernames with Python

I'd like to scrape usernames from an insta user, that seems very easy to do but I don't know enough to do it with Python. Can anyone help me out? I've seen this piece of code for scraping which I think can be useful but I'm not sure how to use it.

Thanks.

from selenium import webdriver
from bs4 import BeautifulSoup

driver= webdriver.Chrome()

driver.get('https://www.instagram.com/michaeljackson/')
soup = BeautifulSoup(driver.page_source,"lxml")
driver.quit()

for item in soup.select('._o6mpc'):
    name = item.select('._kc4z2')[0].text
    followers= item.select('._fd86t')[1].text
following = item.select('._fd86t')[2].text
    print('Name :{}\nFollowers :{}\nFollowing :
{}'.format(name,followers,following))

Upvotes: 0

Views: 1895

Answers (1)

Naveen Honest Raj K
Naveen Honest Raj K

Reputation: 362

I suggest you to use a grammar check before you post the question. Cool. So, as we can see the code, it is a very small scraping code. You need to follow this before running the code.

There are three libraries you need to run the code.

  1. Selenium pip install -U selenium.
  2. BeautifulSoup pip install -U bs4
  3. Lxml pip install -U lxml

Then download the chrome driver from https://sites.google.com/a/chromium.org/chromedriver/

Then run the code by python code.py

P.S. I hope you have Python in your system.

Upvotes: 1

Related Questions