Created
October 17, 2019 05:06
-
-
Save jesusmartinoza/4240d0c8e8b7a272f23f39d985284ded to your computer and use it in GitHub Desktop.
Simple Web Scrapper using Selenium and Beautiful Soup. Example, download Pokemon sprites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting, it's just great! thank you very much for the contribution my friend.