Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
Archives
Today
Total
관리 메뉴

codingfarm

duelyst 이미지 긁어오기 본문

Programming Language/Python

duelyst 이미지 긁어오기

scarecrow1992 2020. 7. 31. 15:57

한번도 해본적은 없지만 도트이미지가 맘에들어서 구경했던 게임입니다.

오랜만에 소식을 찾아보니 서버종료했더군요

 

그래도 이미지 파일들 퀼리티가 좋아서 2d게임 만들때 더미데이터로 쓰기위해 다 다운받으려 했습니다.

https://bagoum.com/cardsort

 

Card Sorting

 

bagoum.com

몇몇 사이트가 있었지만

위 사이트가 모든 카드 정보들이 일렬로 나열되 있어서 접근성이 좋았습니다.

게임상에 있는 모든 카드가 다 있는건지는 모르겠지만

파이썬을 이용해 사이트에 있는 모든 카드를 다운받도록 했습니다.

 

 

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import os
import urllib.request
 
 
 
first_url = "https://bagoum.com"
 
def GetPartLength(str, open_tag):
    length = 0
    close_tag = "/" + open_tag
 
    #시작태그 지점까지 이동한다.
    open_tag_index = str.find(open_tag) - 1
    length += open_tag_index
    str = str[open_tag_index:]
 
    #시작태그의 길이만큼 넘어간다.
    open_tag_length = str.find(">"+ 1
    open_tag_index = 0
    length += open_tag_length
    str = str[open_tag_length:]
 
    while True:
        #시작태그를 하나 넘겼지만
        #또 시작태그가 나올수도, 끝태그가 나올수도 있다
        a = str.find(open_tag)
        b = str.find(close_tag)
 
        if(a > b) or (a==-1):
            return len(close_tag) + 2 + b + length
        else:
            ret = GetPartLength(str, open_tag)
            length += ret
            str = str[ret:]
 
 
 
# url 주소에 있는 gif를 다운로드 한다.
def download_image(url, faction, name):
    #print(url)
    f = urllib.request.urlopen(url)
    s = f.read().decode("utf-8")
 
    #str = s[s.find("<div class=\"cardanims\">"):]
 
    index = s.find("<div class=\"cardanims\">")
    length = GetPartLength((s[index:]), "div")
 
    #print(s[index:index + length])
    s = s[index : index + length]
    s = s[5:]
    key1 = "<div class=\"cardanimhold\">"
    key2 = "<div class=\"animtypename\">"
 
 
    directory = os.getcwd() + "\\cards\\" + faction + "\\"+name
    #print(directory)
    if(os.path.isdir(directory)):
        print("exist")
    else:
        os.makedirs(directory)
        #print("none")
 
    while True:
        index = s.find(key1)
        if index == -1:
            break
        s = s[index:]
        length = GetPartLength(s, "div")
        str = s[:length]
        s = s[len(key1):]
        str = str[str.find(">"+ 1:]
        i=0
 
        while True:
 
            index = str.find("src")
            if index == -1:
                break
            #link = str[str.find("src") + 5 : str.find(">") - 1]
            link = str[str.find("src"+ 5:]
            link = link[: link.find(">")-1]
            #print(first_url + link)
            str = str[str.find(">"+ 1 : ]
            i = i+1
 
            filename = link[link.find("/images/GIFs/"):]
            filename = filename[len("/images/GIFs/"):]
            filename = filename[filename.find("/")+1:]
            if(filename == ""):
                continue
            #print(directory + "\\" + filename)
 
            #first_url + link 의 경로에서 공백을 모두 %20 으로 바꾼다.
            #파일경로에서 \를 모두다 \\로 바꾼다.
 
            str1 = first_url + link
            str1 = str1.strip().replace(" ""%20")
            str2 = directory + "\\" + filename
 
 
            if (not os.path.isfile(str2)):
                try:
                    urllib.request.urlretrieve(str1, str2)
                except urllib.request.HTTPError as e:
                    err = e.read()
                    code = e.getcode()
                    print(code)  ## 404
 
            """
            if(not os.path.isfile(str2)):
                x = urllib.request.urlopen(str1)
                xx = x.read().decode("utf-8")
                xxx = xx[xx.find("<title>"):]
                xxx = xxx[:xxx.find("</title>")]
                if xxx.find("404") == -1:
                    urllib.request.urlretrieve(str1, str2)
                """
 
 
url = "https://bagoum.com/cardsort"
 
= urllib.request.urlopen(url)
= f.read().decode("utf-8")
= s[s.find("body"):]
= s[s.find("div id=\"cardbody\""):]
length = len("div id=\"cardbody\" style=\"text-align: center\">")
= s[length:]
 
 
"""
url = "https://bagoum.com/images/GIFs/Ciphyron%20Ascendant/Ciphyron%20Ascendant_castloop.gif"
try:
    res = urllib.request.urlopen(url)
    print(res.status)
except urllib.request.HTTPError as e:
    err = e.read()
    code = e.getcode()
    print(code) ## 404
"""
 
"""
url = "https://bagoum.com/images/GIFs/Ciphyron%20Ascendant/Ciphyron%20Ascendant_idle.gif"
try:
    urllib.request.urlretrieve(url, "E:\\abc.gif")
except urllib.request.HTTPError as e:
    err = e.read()
    code = e.getcode()
    print(code) ## 404
"""
 
#print(os.getcwd())
 
data_original = "data-original=\"/images/cards/"
for i in range(0,933):
 
    start = s.find("href")
    if start == -1:
        break
 
    s = s[start + 6:]
    faction = s[s.find(data_original)+len(data_original):]
    name = faction
    faction=faction[:faction.find("/")]
    name = name[name.find("/")+1:]
    name = name[:name.find(".png")]
 
    cardimage = s[s.find("data-original="+ len("data-original="+ 1:]
    cardimage = cardimage[:cardimage.find("\"")]
    cardimage = first_url + cardimage
    directory = os.getcwd() + "\\cards\\" + faction + "\\" + name + ".png"
 
    print(name + " : " + str(i))
 
    end = s.find(">")-1
    second_url = s[:end]
    #print(second_url)
    s = s[end:]
 
    if i == 18 or i == 199:
        continue
 
 
    download_image(first_url + second_url, faction, name)
 
    try:
        urllib.request.urlretrieve(cardimage, directory)
    except urllib.request.HTTPError as e:
        err = e.read()
        code = e.getcode()
        print(code)  ## 404
 
 
cs

 

 

 

일부 몇몇 카드들이 기존의 규칙을 어긴채 링크 접근이 되더군요

따로 조건을 작성해서 추가 조치를 해도 되겠지만 그런부분은 그냥 수동으로 직접 처리해 주었습니다.

다 작성하고 보니 beautiful soup라는 웹 크롤링을 쉽게해주는 파이썬 라이브러리가 있더군요

기회가 있다면 한번 배워봐야겠습니다.

 

https://drive.google.com/drive/folders/1xAn_cNFLy6dCsOI-mgHHGaKOIPLwzqcg?usp=sharing

진영별로 정리한 카드 이미지들은 위 링크에서 받을 수 있습니다.

 

 

'Programming Language > Python' 카테고리의 다른 글

파이썬 참고용 코드  (0) 2021.04.02
Comments