質問編集履歴
3
誤字
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
スクレイピング
|
1
|
+
スクレイピングの方法を
|
test
CHANGED
@@ -1,135 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
[https://search.yahoo.co.jp/image/search?p=%E9%BD%8B%E8%97%A4%E9%A3%9B%E9%B3%A5&ei=UTF-8&ts=5054&aq=-1&ai=5nla78HlQtWWxjt2WXYh7A&fr=top_ga1_sa](https://search.yahoo.co.jp/image/search?p=%E9%BD%8B%E8%97%A4%E9%A3%9B%E9%B3%A5&ei=UTF-8&ts=5054&aq=-1&ai=5nla78HlQtWWxjt2WXYh7A&fr=top_ga1_sa)の画像をすべてダウンロードしたいです。
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
しかし、ダウンロードできたのは[https://search.yahoo.co.jp/image/search?p=%E9%BD%8B%E8%97%A4%E9%A3%9B%E9%B3%A5&ei=UTF-8&ts=5054&aq=-1&ai=5nla78HlQtWWxjt2WXYh7A&fr=top_ga1_sa#mode%3Ddetail%26index%3D20%26st%3D401.6842041015625](https://search.yahoo.co.jp/image/search?p=%E9%BD%8B%E8%97%A4%E9%A3%9B%E9%B3%A5&ei=UTF-8&ts=5054&aq=-1&ai=5nla78HlQtWWxjt2WXYh7A&fr=top_ga1_sa#mode%3Ddetail%26index%3D20%26st%3D401.6842041015625)の1枚のみ。
|
1
|
+
**### 調べましたがわかりませんでした。**
|
10
2
|
|
11
3
|
|
12
4
|
|
13
5
|
|
14
6
|
|
15
|
-
### コード(Python)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
import requests
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
from bs4 import BeautifulSoup
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
page_url = "https://search.yahoo.co.jp/image/search?p=%E9%BD%8B%E8%97%A4%E9%A3%9B%E9%B3%A5&ei=UTF-8&ts=2790&aq=-1&ai=zW_mrHpGRMqKAX6fzsoGZA&fr=top_ga1_sa"
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
r = requests.get(page_url)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
soup = BeautifulSoup(r.text,features="html.parser")
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
soup.find_all("img",attrs={"alt":"「齋藤飛鳥」の画像検索結果"})
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
img_tags = soup.find_all("img",attrs={"alt":"「齋藤飛鳥」の画像検索結果"})
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
7
|
+
どなたかおしえください。
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
for img_tag in img_tags:
|
56
|
-
|
57
|
-
url = img_tag.get("src")
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
img_urls.append(url)
|
62
|
-
|
63
|
-
print(url)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
def download_image(url, file_path):
|
68
|
-
|
69
|
-
r = requests.get(url, stream=True)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
if r.status_code == 200:
|
74
|
-
|
75
|
-
with open(file_path, "wb") as f:
|
76
|
-
|
77
|
-
f.write(r.content)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
!mkdir images
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
download_image(url=img_urls[0], file_path="images/1.jpg")
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
from google.colab import drive
|
90
|
-
|
91
|
-
drive.mount('./gdrive')
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
def save_file(file_path):
|
96
|
-
|
97
|
-
upload_file = drive.CreateFile()
|
98
|
-
|
99
|
-
upload_file.SetContentFile(file_path)
|
100
|
-
|
101
|
-
up_file.Upload()
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
import os
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
google_drive_save_dir = "./gdrive/My Drive/Colab Notebooks/つくプロ/スクレイピング_齋藤飛鳥/images"
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
for index, url in enumerate(img_urls):
|
114
|
-
|
115
|
-
file_name = "{}.jpg".format(index)
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
print(file_name)
|
120
|
-
|
121
|
-
image_path = os.path.join(google_drive_save_dir, file_name)
|
122
|
-
|
123
|
-
print(image_path)
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
download_image(url=url, file_path=image_path)
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
**どこを直せば、全ての画像をダウンロードできますか?**
|
2
修正
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
1
脱字
test
CHANGED
File without changes
|
test
CHANGED
@@ -130,4 +130,6 @@
|
|
130
130
|
|
131
131
|
|
132
132
|
|
133
|
+
|
134
|
+
|
133
|
-
どこを直せば、全ての画像をダウンロードできますか?
|
135
|
+
**どこを直せば、全ての画像をダウンロードできますか?**
|