質問編集履歴
8
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -96,4 +96,6 @@
|
|
96
96
|
|
97
97
|
KeyError: 'MMM'
|
98
98
|
|
99
|
+
|
100
|
+
|
99
101
|
```
|
7
文法修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,9 +2,45 @@
|
|
2
2
|
|
3
3
|
ご指摘、ご教授お願いします。
|
4
4
|
|
5
|
-
![イメージ説明](8ffd12396ebde8cc686e317452ab27f0.png)
|
6
5
|
|
6
|
+
|
7
|
+
```python
|
8
|
+
|
9
|
+
import requests
|
10
|
+
|
11
|
+
import json
|
12
|
+
|
13
|
+
↓
|
14
|
+
|
15
|
+
apikey = "MMM"
|
16
|
+
|
17
|
+
↓
|
18
|
+
|
19
|
+
cities = ["London,UK", "Tokyo,JP", "New York,US"]
|
20
|
+
|
21
|
+
↓
|
22
|
+
|
7
|
-
|
23
|
+
api = "http://api.openweathermap.org/data/2.5/forecast?q=Tokyo&APPID={MMM}"
|
24
|
+
|
25
|
+
↓
|
26
|
+
|
27
|
+
k2c =lambda k: k - 273.15
|
28
|
+
|
29
|
+
↓
|
30
|
+
|
31
|
+
for name in cities:
|
32
|
+
|
33
|
+
print("London,UK", "Tokyo,JP", "New York,US")
|
34
|
+
|
35
|
+
↓
|
36
|
+
|
37
|
+
for name in cities:
|
38
|
+
|
39
|
+
print("London,UK", "Tokyo,JP", "New York,US")
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
エラー内容。
|
8
44
|
|
9
45
|
```python
|
10
46
|
|
@@ -36,216 +72,28 @@
|
|
36
72
|
|
37
73
|
print("")
|
38
74
|
|
39
|
-
|
75
|
+
↓
|
40
|
-
|
41
|
-
エラーコード
|
42
|
-
|
43
|
-
```python
|
44
76
|
|
45
77
|
London,UK Tokyo,JP New York,US
|
46
78
|
|
47
79
|
---------------------------------------------------------------------------
|
48
80
|
|
49
|
-
|
81
|
+
KeyError Traceback (most recent call last)
|
50
82
|
|
51
|
-
<ipython-input-6
|
83
|
+
<ipython-input-126-8a8e428ed215> in <module>
|
52
84
|
|
53
|
-
|
85
|
+
2 print("London,UK", "Tokyo,JP", "New York,US")
|
54
86
|
|
55
|
-
|
87
|
+
3
|
56
88
|
|
57
|
-
---->
|
89
|
+
----> 4 url = api.format(city=name, key=apikey)
|
58
90
|
|
59
|
-
|
91
|
+
5 r = requests.get(url)
|
60
92
|
|
61
|
-
|
93
|
+
6 data = json.loads(r.text)
|
62
94
|
|
63
95
|
|
64
96
|
|
65
|
-
~/.pyenv/versions/3.8.0/lib/python3.8/json/__init__.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
|
66
|
-
|
67
|
-
355 parse_int is None and parse_float is None and
|
68
|
-
|
69
|
-
356 parse_constant is None and object_pairs_hook is None and not kw):
|
70
|
-
|
71
|
-
--> 357 return _default_decoder.decode(s)
|
72
|
-
|
73
|
-
358 if cls is None:
|
74
|
-
|
75
|
-
359 cls = JSONDecoder
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
~/.pyenv/versions/3.8.0/lib/python3.8/json/decoder.py in decode(self, s, _w)
|
80
|
-
|
81
|
-
335
|
82
|
-
|
83
|
-
|
97
|
+
KeyError: 'MMM'
|
84
|
-
|
85
|
-
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
|
86
|
-
|
87
|
-
338 end = _w(s, end).end()
|
88
|
-
|
89
|
-
339 if end != len(s):
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
~/.pyenv/versions/3.8.0/lib/python3.8/json/decoder.py in raw_decode(self, s, idx)
|
94
|
-
|
95
|
-
353 obj, end = self.scan_once(s, idx)
|
96
|
-
|
97
|
-
354 except StopIteration as err:
|
98
|
-
|
99
|
-
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
|
100
|
-
|
101
|
-
356 return obj, end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
|
106
|
-
|
107
|
-
|
108
98
|
|
109
99
|
```
|
110
|
-
|
111
|
-
```python
|
112
|
-
|
113
|
-
print(r.text)
|
114
|
-
|
115
|
-
↓
|
116
|
-
|
117
|
-
<!DOCTYPE html>
|
118
|
-
|
119
|
-
<html>
|
120
|
-
|
121
|
-
<head>
|
122
|
-
|
123
|
-
<title>The page you were looking for doesn't exist (404)</title>
|
124
|
-
|
125
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
126
|
-
|
127
|
-
<style>
|
128
|
-
|
129
|
-
body {
|
130
|
-
|
131
|
-
background-color: #EFEFEF;
|
132
|
-
|
133
|
-
color: #2E2F30;
|
134
|
-
|
135
|
-
text-align: center;
|
136
|
-
|
137
|
-
font-family: arial, sans-serif;
|
138
|
-
|
139
|
-
margin: 0;
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
div.dialog {
|
146
|
-
|
147
|
-
width: 95%;
|
148
|
-
|
149
|
-
max-width: 33em;
|
150
|
-
|
151
|
-
margin: 4em auto 0;
|
152
|
-
|
153
|
-
}
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
div.dialog > div {
|
158
|
-
|
159
|
-
border: 1px solid #CCC;
|
160
|
-
|
161
|
-
border-right-color: #999;
|
162
|
-
|
163
|
-
border-left-color: #999;
|
164
|
-
|
165
|
-
border-bottom-color: #BBB;
|
166
|
-
|
167
|
-
border-top: #B00100 solid 4px;
|
168
|
-
|
169
|
-
border-top-left-radius: 9px;
|
170
|
-
|
171
|
-
border-top-right-radius: 9px;
|
172
|
-
|
173
|
-
background-color: white;
|
174
|
-
|
175
|
-
padding: 7px 12% 0;
|
176
|
-
|
177
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
h1 {
|
184
|
-
|
185
|
-
font-size: 100%;
|
186
|
-
|
187
|
-
color: #730E15;
|
188
|
-
|
189
|
-
line-height: 1.5em;
|
190
|
-
|
191
|
-
}
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
div.dialog > p {
|
196
|
-
|
197
|
-
margin: 0 0 1em;
|
198
|
-
|
199
|
-
padding: 1em;
|
200
|
-
|
201
|
-
background-color: #F7F7F7;
|
202
|
-
|
203
|
-
border: 1px solid #CCC;
|
204
|
-
|
205
|
-
border-right-color: #999;
|
206
|
-
|
207
|
-
border-left-color: #999;
|
208
|
-
|
209
|
-
border-bottom-color: #999;
|
210
|
-
|
211
|
-
border-bottom-left-radius: 4px;
|
212
|
-
|
213
|
-
border-bottom-right-radius: 4px;
|
214
|
-
|
215
|
-
border-top-color: #DADADA;
|
216
|
-
|
217
|
-
color: #666;
|
218
|
-
|
219
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
</style>
|
224
|
-
|
225
|
-
</head>
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
<body>
|
230
|
-
|
231
|
-
<!-- This file lives in public/404.html -->
|
232
|
-
|
233
|
-
<div class="dialog">
|
234
|
-
|
235
|
-
<div>
|
236
|
-
|
237
|
-
<h1>The page you were looking for doesn't exist.</h1>
|
238
|
-
|
239
|
-
<p>You may have mistyped the address or the page may have moved.</p>
|
240
|
-
|
241
|
-
</div>
|
242
|
-
|
243
|
-
<p>If you are the application owner check the logs for more information.</p>
|
244
|
-
|
245
|
-
</div>
|
246
|
-
|
247
|
-
</body>
|
248
|
-
|
249
|
-
</html>
|
250
|
-
|
251
|
-
```
|
6
変更点追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
5
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
ご指摘、ご教授お願いします。
|
4
4
|
|
5
|
+
![イメージ説明](8ffd12396ebde8cc686e317452ab27f0.png)
|
6
|
+
|
5
7
|
[スクレイピング先のLink](https://home.openweathermap.org/api_keys)
|
6
8
|
|
7
9
|
```python
|
4
変更点追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
ご指摘、ご教授お願いします。
|
4
4
|
|
5
|
-
|
5
|
+
[スクレイピング先のLink](https://home.openweathermap.org/api_keys)
|
6
6
|
|
7
7
|
```python
|
8
8
|
|
3
変更点追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -105,3 +105,145 @@
|
|
105
105
|
|
106
106
|
|
107
107
|
```
|
108
|
+
|
109
|
+
```python
|
110
|
+
|
111
|
+
print(r.text)
|
112
|
+
|
113
|
+
↓
|
114
|
+
|
115
|
+
<!DOCTYPE html>
|
116
|
+
|
117
|
+
<html>
|
118
|
+
|
119
|
+
<head>
|
120
|
+
|
121
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
122
|
+
|
123
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
124
|
+
|
125
|
+
<style>
|
126
|
+
|
127
|
+
body {
|
128
|
+
|
129
|
+
background-color: #EFEFEF;
|
130
|
+
|
131
|
+
color: #2E2F30;
|
132
|
+
|
133
|
+
text-align: center;
|
134
|
+
|
135
|
+
font-family: arial, sans-serif;
|
136
|
+
|
137
|
+
margin: 0;
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
div.dialog {
|
144
|
+
|
145
|
+
width: 95%;
|
146
|
+
|
147
|
+
max-width: 33em;
|
148
|
+
|
149
|
+
margin: 4em auto 0;
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
div.dialog > div {
|
156
|
+
|
157
|
+
border: 1px solid #CCC;
|
158
|
+
|
159
|
+
border-right-color: #999;
|
160
|
+
|
161
|
+
border-left-color: #999;
|
162
|
+
|
163
|
+
border-bottom-color: #BBB;
|
164
|
+
|
165
|
+
border-top: #B00100 solid 4px;
|
166
|
+
|
167
|
+
border-top-left-radius: 9px;
|
168
|
+
|
169
|
+
border-top-right-radius: 9px;
|
170
|
+
|
171
|
+
background-color: white;
|
172
|
+
|
173
|
+
padding: 7px 12% 0;
|
174
|
+
|
175
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
h1 {
|
182
|
+
|
183
|
+
font-size: 100%;
|
184
|
+
|
185
|
+
color: #730E15;
|
186
|
+
|
187
|
+
line-height: 1.5em;
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
div.dialog > p {
|
194
|
+
|
195
|
+
margin: 0 0 1em;
|
196
|
+
|
197
|
+
padding: 1em;
|
198
|
+
|
199
|
+
background-color: #F7F7F7;
|
200
|
+
|
201
|
+
border: 1px solid #CCC;
|
202
|
+
|
203
|
+
border-right-color: #999;
|
204
|
+
|
205
|
+
border-left-color: #999;
|
206
|
+
|
207
|
+
border-bottom-color: #999;
|
208
|
+
|
209
|
+
border-bottom-left-radius: 4px;
|
210
|
+
|
211
|
+
border-bottom-right-radius: 4px;
|
212
|
+
|
213
|
+
border-top-color: #DADADA;
|
214
|
+
|
215
|
+
color: #666;
|
216
|
+
|
217
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
</style>
|
222
|
+
|
223
|
+
</head>
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
<body>
|
228
|
+
|
229
|
+
<!-- This file lives in public/404.html -->
|
230
|
+
|
231
|
+
<div class="dialog">
|
232
|
+
|
233
|
+
<div>
|
234
|
+
|
235
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
236
|
+
|
237
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
238
|
+
|
239
|
+
</div>
|
240
|
+
|
241
|
+
<p>If you are the application owner check the logs for more information.</p>
|
242
|
+
|
243
|
+
</div>
|
244
|
+
|
245
|
+
</body>
|
246
|
+
|
247
|
+
</html>
|
248
|
+
|
249
|
+
```
|
2
変更点追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
1
コード追加
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
python スクレイピング json.loads() JSONDecodeError
|
test
CHANGED
File without changes
|