質問編集履歴
2
GitHub追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -105,3 +105,9 @@
|
|
105
105
|
f1.write(html_doc)
|
106
106
|
|
107
107
|
```
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
# GitHubにも上げました!
|
112
|
+
|
113
|
+
[O'Reilly Scraping](https://github.com/Yukiya025/CommerceScraper)
|
1
完成コード追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -67,3 +67,41 @@
|
|
67
67
|
|
68
68
|
|
69
69
|

|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
# できましたー(≧∇≦)
|
74
|
+
|
75
|
+
hayataka2049様のアドバイスで`r.encoding = r.apparent_encoding`を追加したら日本語がきちんと表示されるようになりました<3
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
**完成コード**
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
import requests
|
84
|
+
|
85
|
+
import warnings
|
86
|
+
|
87
|
+
warnings.filterwarnings('ignore')
|
88
|
+
|
89
|
+
r = requests.get("https://www.oreilly.co.jp/catalog/")
|
90
|
+
|
91
|
+
r.encoding = r.apparent_encoding
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
html_doc = r.text
|
96
|
+
|
97
|
+
soup = BeautifulSoup(html_doc)
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
print(soup.title)
|
102
|
+
|
103
|
+
f1 = open('r.txt', 'w')
|
104
|
+
|
105
|
+
f1.write(html_doc)
|
106
|
+
|
107
|
+
```
|