質問編集履歴
2
コード訂正
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,8 +10,8 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
###該当のソースコード
|
13
|
-
``Python
|
14
13
|
|
14
|
+
```Python
|
15
15
|
import csv
|
16
16
|
import requests
|
17
17
|
from bs4 import BeautifulSoup
|
@@ -32,6 +32,9 @@
|
|
32
32
|
writer.writerow(header)
|
33
33
|
writer.writerows(body)
|
34
34
|
|
35
|
+
```
|
36
|
+
|
37
|
+
|
35
38
|
###試したこと
|
36
39
|
for文(for food in soup.findAll(class_='pc2015-item-inner pc2015-for-member'):)はprintするとすべての情報を書き出すことができるのでfor文は間違ってはいないと思います。
|
37
40
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
1
質問内容の変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
###前提・実現したいこと
|
2
2
|
プログラミング初心者です。ご教授お願いします。
|
3
|
-
イオンネットスーパー(https://www.aeonnetshop.com/shop/r/r5603_n01050000001160_v80/)での野菜の商品名と値段のスクレイピング結果をcsvに書き出したい。
|
3
|
+
イオンネットスーパー(https://www.aeonnetshop.com/shop/r/r5603_n01050000001160_v80/)でのすべての野菜の商品名と値段のスクレイピング結果をcsvに書き出したい。
|
4
|
+
|
5
|
+
|
4
6
|
###発生している問題・エラーメッセージ
|
5
|
-
|
7
|
+
ホームページ上の80種の野菜のうち、80番目の野菜のみcsvに書き出すことができているが、他の79種の野菜の情報が書き出されない。
|
6
|
-
```
|
7
8
|
|
8
9
|
|
10
|
+
|
11
|
+
|
9
12
|
###該当のソースコード
|
10
13
|
``Python
|
11
14
|
|
15
|
+
import csv
|
12
16
|
import requests
|
13
17
|
from bs4 import BeautifulSoup
|
14
18
|
|
@@ -17,7 +21,18 @@
|
|
17
21
|
soup.find(class_='pc2015-item-inner pc2015-for-member')
|
18
22
|
|
19
23
|
for food in soup.findAll(class_='pc2015-item-inner pc2015-for-member'):
|
20
|
-
|
24
|
+
food.find(class_='pc2015-item-name').find('span').string + food.find(class_='pc2015-price-1').find('strong').contents[0] + food.find(class_='pc2015-price-2').find('strong').contents[0]
|
25
|
+
|
21
|
-
|
26
|
+
header = ['name','price1','price2']
|
27
|
+
body = [
|
28
|
+
[food.find(class_='pc2015-item-name').find('span').string,food.find(class_='pc2015-price-1').find('strong').contents[0],food.find(class_='pc2015-price-2').find('strong').contents[0]]
|
29
|
+
]
|
22
|
-
|
30
|
+
with open('food.csv', 'wt',newline='') as csvfile:
|
31
|
+
writer = csv.writer(csvfile)
|
32
|
+
writer.writerow(header)
|
33
|
+
writer.writerows(body)
|
34
|
+
|
35
|
+
###試したこと
|
36
|
+
for文(for food in soup.findAll(class_='pc2015-item-inner pc2015-for-member'):)はprintするとすべての情報を書き出すことができるのでfor文は間違ってはいないと思います。
|
37
|
+
###補足情報(言語/FW/ツール等のバージョンなど)
|
23
|
-
|
38
|
+
より詳細な情報
|