Skip to content

Instantly share code, notes, and snippets.

@jesusmartinoza
Created October 17, 2019 05:06
Show Gist options
  • Save jesusmartinoza/4240d0c8e8b7a272f23f39d985284ded to your computer and use it in GitHub Desktop.
Save jesusmartinoza/4240d0c8e8b7a272f23f39d985284ded to your computer and use it in GitHub Desktop.
Simple Web Scrapper using Selenium and Beautiful Soup. Example, download Pokemon sprites
from selenium import webdriver
from bs4 import BeautifulSoup
import urllib.request
import os
import requests
driver = webdriver.Chrome("./chromedriver")
# Set the URL you want to webscrap from
# Example website with tons of Pokemon Sprites
driver.get('https://pokemondb.net/sprites')
content = driver.page_source
soup = BeautifulSoup(content)
for a in soup.findAll('a',href=True, attrs={'class':'infocard'}):
print('Scrappin from https://pokemondb.net' + a['href'])
driver.get('https://pokemondb.net' + a['href'])
internalSoup = BeautifulSoup(driver.page_source)
i = 0
for c in internalSoup.findAll('img', attrs={'class': 'img-fixed'}):
# Don't download sprites from Pokemon backs
if 'Back' not in c['alt']:
# Download image and save it using the following notation.
# Pikachu-1.png, Pikachu-2.png, etc.
out_image = "sprites/{}-{}.png".format(a.text.strip(), i)
r = requests.get(c['src'])
with open(out_image, 'wb') as outfile:
outfile.write(r.content)
i += 1
@x0nu11byt3
Copy link

Interesting, it's just great! thank you very much for the contribution my friend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment