質問編集履歴
3
ソースコード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,14 +52,18 @@
|
|
52
52
|
|
53
53
|
import cv2
|
54
54
|
|
55
|
-
|
55
|
+
import traceback
|
56
|
-
|
56
|
+
|
57
|
+
|
58
|
+
|
57
|
-
df = pd.read_csv('/Users/
|
59
|
+
df = pd.read_csv('/Users/yonedakouki/banggood/img_ban.csv',
|
58
60
|
|
59
61
|
encoding='cp932', dtype=object)
|
60
62
|
|
61
63
|
|
62
64
|
|
65
|
+
|
66
|
+
|
63
67
|
headers = {
|
64
68
|
|
65
69
|
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0"}
|
@@ -80,7 +84,7 @@
|
|
80
84
|
|
81
85
|
url_extension = url_separate[1].replace('URL', '')
|
82
86
|
|
83
|
-
url_extension = url_extension.replace('#u
|
87
|
+
url_extension = url_extension.replace('#Yosuke', '')
|
84
88
|
|
85
89
|
|
86
90
|
|
@@ -92,11 +96,13 @@
|
|
92
96
|
|
93
97
|
mem = urllib.request.urlopen(request).read()
|
94
98
|
|
95
|
-
|
99
|
+
# ファイルへの保存
|
100
|
+
|
101
|
+
# url_extension
|
96
102
|
|
97
103
|
x = row['code'] + column_name.replace('URL', '') + ".jpeg"
|
98
104
|
|
99
|
-
with open('/Users/
|
105
|
+
with open('/Users/yonedakouki/banggood/u/' + x, mode="wb") as f:
|
100
106
|
|
101
107
|
f.write(mem)
|
102
108
|
|
@@ -110,33 +116,41 @@
|
|
110
116
|
|
111
117
|
else:
|
112
118
|
|
113
|
-
img = cv2.imread('/Users/
|
119
|
+
img = cv2.imread('/Users/yonedakouki/banggood/u/' + x)
|
114
|
-
|
115
|
-
print(img.shape)
|
116
120
|
|
117
121
|
img2 = cv2.resize(img, dsize=None, fx=0.5, fy=0.5)
|
118
122
|
|
119
123
|
cv2.imwrite(
|
120
124
|
|
121
|
-
'/
|
125
|
+
'/Users/yonedakouki/banggood/u/' + x, img2)
|
122
126
|
|
123
127
|
|
124
128
|
|
125
129
|
except urllib.error.HTTPError:
|
126
130
|
|
127
|
-
print("エラー")
|
131
|
+
print("!!! HTTP エラー")
|
132
|
+
|
133
|
+
traceback.print_exc()
|
134
|
+
|
135
|
+
except Exception as err:
|
136
|
+
|
137
|
+
print("!!! HTTP エラー以外のエラー")
|
138
|
+
|
139
|
+
traceback.print_exc()
|
128
140
|
|
129
141
|
time.sleep(1)
|
130
142
|
|
131
143
|
|
132
144
|
|
133
|
-
except
|
145
|
+
except Exception as err:
|
146
|
+
|
134
|
-
|
147
|
+
print("!!! URL 関連のエラー")
|
148
|
+
|
135
|
-
print(
|
149
|
+
print(
|
136
|
-
|
150
|
+
|
137
|
-
|
151
|
+
"CSVに定義されている元のURL[" + row[column_name] + "]に問題があるようです。スキップします。")
|
138
|
-
|
139
|
-
|
152
|
+
|
153
|
+
|
140
154
|
|
141
155
|
else:
|
142
156
|
|
@@ -146,6 +160,10 @@
|
|
146
160
|
|
147
161
|
f.close()
|
148
162
|
|
163
|
+
print("正常に終了しました。")
|
164
|
+
|
165
|
+
|
166
|
+
|
149
167
|
|
150
168
|
|
151
169
|
```ここに言語名を入力
|
2
試したこと修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,25 @@
|
|
14
14
|
|
15
15
|
```
|
16
16
|
|
17
|
+
Traceback (most recent call last):
|
18
|
+
|
19
|
+
File "/Users/username/Downloads/image_downloader.py", line 25, in <module>
|
20
|
+
|
21
|
+
request = urllib.request.Request(
|
22
|
+
|
23
|
+
File "/Users/username/.pyenv/versions/3.8.0/lib/python3.8/urllib/request.py", line 328, in __init__
|
24
|
+
|
25
|
+
self.full_url = url
|
26
|
+
|
27
|
+
File "/Users/username/.pyenv/versions/3.8.0/lib/python3.8/urllib/request.py", line 354, in full_url
|
28
|
+
|
17
|
-
|
29
|
+
self._parse()
|
30
|
+
|
31
|
+
File "/Users/username/.pyenv/versions/3.8.0/lib/python3.8/urllib/request.py", line 383, in _parse
|
32
|
+
|
33
|
+
raise ValueError("unknown url type: %r" % self.full_url)
|
34
|
+
|
35
|
+
ValueError: unknown url type: 't'
|
18
36
|
|
19
37
|
```
|
20
38
|
|
@@ -140,10 +158,52 @@
|
|
140
158
|
|
141
159
|
|
142
160
|
|
161
|
+
python update 2.7.1→3.9.0へ
|
162
|
+
|
163
|
+
pandas downgrade 0.24.2へ
|
164
|
+
|
165
|
+
|
166
|
+
|
143
|
-
|
167
|
+
エラーログ確認
|
168
|
+
|
169
|
+
!!! URL 関連のエラー
|
170
|
+
|
171
|
+
Traceback (most recent call last):
|
172
|
+
|
173
|
+
File "/Users/username/Downloads/image_downloader.py", line 25, in <module>
|
174
|
+
|
175
|
+
request = urllib.request.Request(
|
176
|
+
|
177
|
+
File "/Users/username/.pyenv/versions/3.8.0/lib/python3.8/urllib/request.py", line 328, in __init__
|
178
|
+
|
179
|
+
self.full_url = url
|
180
|
+
|
181
|
+
File "/Users/username/.pyenv/versions/3.8.0/lib/python3.8/urllib/request.py", line 354, in full_url
|
182
|
+
|
183
|
+
self._parse()
|
184
|
+
|
185
|
+
File "/Users/username/.pyenv/versions/3.8.0/lib/python3.8/urllib/request.py", line 383, in _parse
|
186
|
+
|
187
|
+
raise ValueError("unknown url type: %r" % self.full_url)
|
188
|
+
|
189
|
+
ValueError: unknown url type: 't'
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
>>>URLが記載されているcsvファイルを確認すると、URLではなく”t”のみ記載されたセルがあった
|
194
|
+
|
195
|
+
→”t”を削除してもプログラムは停止する。
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
>>>上記エラーが出ても、すぐには停止せず、数枚画像をダウンロードをしてから停止した。
|
200
|
+
|
201
|
+
>>>上記エラーが出ずに停止する場合もある。
|
202
|
+
|
203
|
+
|
144
204
|
|
145
205
|
|
146
206
|
|
147
207
|
### 補足情報(FW/ツールのバージョンなど)
|
148
208
|
|
149
|
-
python 2.7
|
209
|
+
python 2.7 → 3.9.0へupdate
|
1
Markdown記法へ編集しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
### 該当のソースコード
|
24
24
|
|
25
|
-
import urllib.request
|
25
|
+
```import urllib.request
|
26
26
|
|
27
27
|
import sys
|
28
28
|
|
@@ -36,7 +36,7 @@
|
|
36
36
|
|
37
37
|
|
38
38
|
|
39
|
-
df = pd.read_csv('/Users/
|
39
|
+
df = pd.read_csv('/Users/username/banggood/img_ban.csv',
|
40
40
|
|
41
41
|
encoding='cp932', dtype=object)
|
42
42
|
|
@@ -62,7 +62,7 @@
|
|
62
62
|
|
63
63
|
url_extension = url_separate[1].replace('URL', '')
|
64
64
|
|
65
|
-
url_extension = url_extension.replace('#
|
65
|
+
url_extension = url_extension.replace('#username', '')
|
66
66
|
|
67
67
|
|
68
68
|
|
@@ -78,7 +78,7 @@
|
|
78
78
|
|
79
79
|
x = row['code'] + column_name.replace('URL', '') + ".jpeg"
|
80
80
|
|
81
|
-
with open('/Users/
|
81
|
+
with open('/Users/username/banggood/u/' + x, mode="wb") as f:
|
82
82
|
|
83
83
|
f.write(mem)
|
84
84
|
|
@@ -92,7 +92,7 @@
|
|
92
92
|
|
93
93
|
else:
|
94
94
|
|
95
|
-
img = cv2.imread('/Users/
|
95
|
+
img = cv2.imread('/Users/username/banggood/u' + x)
|
96
96
|
|
97
97
|
print(img.shape)
|
98
98
|
|
@@ -100,7 +100,7 @@
|
|
100
100
|
|
101
101
|
cv2.imwrite(
|
102
102
|
|
103
|
-
'/ Users/
|
103
|
+
'/ Users/username/banggood/u' + x, img2)
|
104
104
|
|
105
105
|
|
106
106
|
|
@@ -134,8 +134,6 @@
|
|
134
134
|
|
135
135
|
python
|
136
136
|
|
137
|
-
```
|
138
|
-
|
139
137
|
|
140
138
|
|
141
139
|
### 試したこと
|