I am trying to scrape some img files from IG using selenium and bs4. I have this following script to do it, it seems to work fine, but eventually I'd like it to just print img src
, a sample: https://scontent-lax3-2.cdninstagram.com/vp/2592f6b07f88bfc4bfdf6d73400a04b8/5BA6E998/t51.2885-15/s640x640/sh0.08/e35/28752330_1972627949433283_1816022201220988928_n.jpg
and download images later. But for now I would need some help to just print that img src link without the tags and extras. Thanks for the advice.
Code:
import requests
from bs4 import BeautifulSoup
import selenium.webdriver as webdriver
url = ('https://www.instagram.com/kitties/')
driver = webdriver.Firefox()
driver.get(url)
soup = BeautifulSoup(driver.page_source, 'lxml')
img_url = soup.find_all('img', class_='_2di5p')
print img_url
Just print out the src
of the found images.
imgs= soup.find_all('img', class_='_2di5p')
for img in imgs:
img_url=img["src"]
print img_url
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.