回答編集履歴
1
補足を追加
answer
CHANGED
@@ -7,4 +7,31 @@
|
|
7
7
|
|
8
8
|
```Python
|
9
9
|
img1 = Image.open(io.BytesIO(requests.get(img_url).content))
|
10
|
+
```
|
11
|
+
|
12
|
+
補足: 追記を見ると、質問文に提示されたセルを一部実行していないように見えます。以下のようにまとめて書いたセルを作るか、Jupyterを使わずに単独のファイルとして作成してPythonから実行してください。
|
13
|
+
|
14
|
+
```Python
|
15
|
+
import matplotlib.pyplot as plt
|
16
|
+
import io
|
17
|
+
from PIL import Image
|
18
|
+
import requests
|
19
|
+
from bs4 import BeautifulSoup
|
20
|
+
|
21
|
+
url = 'https://scraping-for-beginner.herokuapp.com/image'
|
22
|
+
res = requests.get(url)
|
23
|
+
|
24
|
+
soup = BeautifulSoup(res.text, 'html.parser')
|
25
|
+
# print(soup)
|
26
|
+
|
27
|
+
img_tag = soup.find('img')
|
28
|
+
# print(img_tag['src'])
|
29
|
+
|
30
|
+
root_url = 'https://scraping-for-beginner.herokuapp.com'
|
31
|
+
img_url = root_url + img_tag['src']
|
32
|
+
# print(img_url)
|
33
|
+
|
34
|
+
img1 = Image.open(io.BytesIO(requests.get(img_url).content))
|
35
|
+
plt.imshow(img1)
|
36
|
+
plt.show()
|
10
37
|
```
|