-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_image_wikia.py
35 lines (28 loc) · 983 Bytes
/
get_image_wikia.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
def download_imag(number):
print('Try to download: ' + str(number))
#set url
img_url = 'http://yugioh.wikia.com/wiki/' + str(number)
try:
#parse url and get img url
s = requests.Session()
r = s.get(img_url)
soup = BeautifulSoup(r.content,"html.parser")
get_class = soup.find(attrs={'class' :'cardtable-cardimage'})
download_url = get_class.findAll('img')[0].get('src')
print('start download')
#download image
download_s = requests.Session()
download_r = download_s.get(download_url)
filename = "img/" + str(number) + ".jpg"
pic_out = file(filename,'w')
pic_out.write(download_r.content)
pic_out.close()
print('download complete')
except:
print('something wrong')
while (True):
get_input = raw_input(">>> Input: ")
download_imag(get_input)