S
S
Sergey Afanasiev2020-07-08 16:39:20
Python
Sergey Afanasiev, 2020-07-08 16:39:20

Parsing an Instagram photo with BeautifulSoup?

Hello!
Sorry for such a simple question, but I want to parse an image from instagram using this link https://www.instagram.com/p/CBxjJe2h_pr/ , but I can’t do anything, if someone has free time, can help out?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
datka, 2020-07-08
@datka

10 seconds of google search...

If you look at the source code for the page, you'll see that some javascript generates the webpage. What you see in the element browser is the webpage after the script has been run, and beautifulsoup just gets the html file. In order to parse the rendered webpage you'll need to use something like Selenium to render the webpage for you.
So, for example, this is how it would look with Selenium:
from bs4 import BeautifulSoup
import selenium.webdriver as webdriver

url = 'http://instagram.com/umnpics/'
driver = webdriver.Firefox()
driver.get(url)

soup = BeautifulSoup(driver.page_source)

for x in soup.findAll('li', {'class':'photo'}):
    print x


soup.findAll('li', {'class':'photo'})change to your needs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question