furas

Python - download FIFA images

Jul 6th, 2018
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup as BS
  3.  
  4. url = 'https://www.fifa.com/worldcup/teams/team/43938/'
  5.  
  6. r = requests.get(url)
  7. soup = BS(r.text)
  8.  
  9. number = 1
  10.  
  11. for svg in soup.find_all('svg'):
  12.     image = svg.find('image')
  13.     if image:
  14.         href = image['xlink:href']
  15.         filename = '{}.jpg'.format(number)
  16.         print('downloading:', number)
  17.  
  18.         r = requests.get(href)
  19.         with open(filename, 'wb') as f:
  20.             f.write(r.content)
  21.  
  22.         number += 1
Add Comment
Please, Sign In to add comment