回答編集履歴
1
補足を追加
answer
CHANGED
@@ -10,4 +10,26 @@
|
|
10
10
|
Excelで読み出すなら Shift JISの方がよいのかな?
|
11
11
|
```Python
|
12
12
|
df.to_csv('output.csv', index=None, encoding="shift_jis")
|
13
|
+
```
|
14
|
+
|
15
|
+
**【一応補足】**
|
16
|
+
現状のコードを修正(素直に実装)するならこんな感じ
|
17
|
+
|
18
|
+
- TABLEの行毎のループ内にさらに列毎ののループを追加して2次元リストを作成
|
19
|
+
- `writerow()` の代わりに `writerows()` を使用して2次元リストを書き出す
|
20
|
+
|
21
|
+
です。
|
22
|
+
|
23
|
+
```Python
|
24
|
+
csvlist=[]
|
25
|
+
for row in rows:
|
26
|
+
rowlist = []
|
27
|
+
for item in row.findAll(["td", "th"]):
|
28
|
+
rowlist.append(item.getText(strip=True))
|
29
|
+
csvlist.append(rowlist)
|
30
|
+
print(csvlist)
|
31
|
+
|
32
|
+
with open("output2.csv","w") as f:
|
33
|
+
writecsv = csv.writer(f, lineterminator='\n')
|
34
|
+
writecsv.writerows(csvlist)
|
13
35
|
```
|