回答編集履歴
2
prettifyに変更
test
CHANGED
@@ -88,7 +88,7 @@
|
|
88
88
|
|
89
89
|
with open('test.html', mode = 'w', encoding = 'utf-8') as fw:
|
90
90
|
|
91
|
-
fw.write(soup)
|
91
|
+
fw.write(soup.prettify())
|
92
92
|
|
93
93
|
```
|
94
94
|
|
1
ファイルの場合を追記
test
CHANGED
@@ -56,7 +56,13 @@
|
|
56
56
|
|
57
57
|
|
58
58
|
|
59
|
+
# ファイルを開く
|
60
|
+
|
61
|
+
soup = BeautifulSoup(open('test.html', encoding='utf-8'), 'html.parser')
|
62
|
+
|
63
|
+
|
64
|
+
|
59
|
-
soup = BeautifulSoup(html, "html.parser")
|
65
|
+
# soup = BeautifulSoup(html, "html.parser")
|
60
66
|
|
61
67
|
|
62
68
|
|
@@ -75,6 +81,14 @@
|
|
75
81
|
# 整形するならこちらで
|
76
82
|
|
77
83
|
# print(soup.prettify())
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
# ファイル保存
|
88
|
+
|
89
|
+
with open('test.html', mode = 'w', encoding = 'utf-8') as fw:
|
90
|
+
|
91
|
+
fw.write(soup)
|
78
92
|
|
79
93
|
```
|
80
94
|
|