回答編集履歴
4
追記
test
CHANGED
@@ -35,3 +35,75 @@
|
|
35
35
|
```
|
36
36
|
|
37
37
|
としてくださいな。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
---
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
◇スタックトレースの読み方
|
46
|
+
|
47
|
+
```Python
|
48
|
+
|
49
|
+
File "python_ex289_ex293.py", line 13, in scrape
|
50
|
+
|
51
|
+
html = r.text() # エラーが発生した時に実行していた行
|
52
|
+
|
53
|
+
TypeError: 'unicode' object is not callable # 実行エラー
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
まず、実行エラーをグーグル翻訳に掛けます。
|
60
|
+
|
61
|
+
TypeError: 'unicode'オブジェクトは呼び出し可能ではありません
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
次に、実行エラーの原因を推測します。
|
66
|
+
|
67
|
+
```Python
|
68
|
+
|
69
|
+
html = r.text()
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
1,代入文なので、htmlは原因となりえません。
|
74
|
+
|
75
|
+
```Python
|
76
|
+
|
77
|
+
r.text()
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
2, 次にrの値がNoneならば、NoneTypeの例外が発生するので、これも違います。
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
よって原因は以下です。
|
86
|
+
|
87
|
+
```Python
|
88
|
+
|
89
|
+
text()
|
90
|
+
|
91
|
+
```
|
92
|
+
|
93
|
+
推測が正しいか[公式ドキュメント](http://docs.python-requests.org/en/master/user/quickstart/#response-content)で確認します。
|
94
|
+
|
95
|
+
```Python
|
96
|
+
|
97
|
+
r.text
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
と括弧なしで記載されています。よって括弧をはずして以下のように。
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
```Python
|
106
|
+
|
107
|
+
html = r.text
|
108
|
+
|
109
|
+
```
|
3
リンク先を変更
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
案としては2つ
|
14
14
|
|
15
|
-
案1,[BeautifulSoup 3.2.1](https://www.crummy.com/software/BeautifulSoup/bs3/documentation.html
|
15
|
+
案1,[BeautifulSoup 3.2.1](https://www.crummy.com/software/BeautifulSoup/bs3/documentation.html)のドキュメントを参考にプログラムを修正する。
|
16
16
|
|
17
17
|
|
18
18
|
|
2
追記
test
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
> BeautifulSoup (3.2.1)
|
1
|
+
> BeautifulSoup (3.2.1)と出たので「ではbsとBeautifulSoupに3をつけてみよう」
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
> ではbsとBeautifulSoupに3をつけてみよう
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
こういう時は公式ドキュメントを探します。キーワードは「BeautifulSoup doc 3.2.1」です、検索すると[BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/)のページがHITします。
|
10
6
|
|
11
7
|
|
12
8
|
|
1
追記
test
CHANGED
@@ -34,7 +34,7 @@
|
|
34
34
|
|
35
35
|
```
|
36
36
|
|
37
|
-
|
37
|
+
pip install beautifulsoup4
|
38
38
|
|
39
39
|
```
|
40
40
|
|