teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

4

追記

2018/08/09 02:18

投稿

umyu
umyu

スコア5846

answer CHANGED
@@ -16,4 +16,40 @@
16
16
  ```
17
17
  pip install beautifulsoup4
18
18
  ```
19
- としてくださいな。
19
+ としてくださいな。
20
+
21
+ ---
22
+
23
+ ◇スタックトレースの読み方
24
+ ```Python
25
+ File "python_ex289_ex293.py", line 13, in scrape
26
+ html = r.text() # エラーが発生した時に実行していた行
27
+ TypeError: 'unicode' object is not callable # 実行エラー
28
+ ```
29
+
30
+ まず、実行エラーをグーグル翻訳に掛けます。
31
+ TypeError: 'unicode'オブジェクトは呼び出し可能ではありません
32
+
33
+ 次に、実行エラーの原因を推測します。
34
+ ```Python
35
+ html = r.text()
36
+ ```
37
+ 1,代入文なので、htmlは原因となりえません。
38
+ ```Python
39
+ r.text()
40
+ ```
41
+ 2, 次にrの値がNoneならば、NoneTypeの例外が発生するので、これも違います。
42
+
43
+ よって原因は以下です。
44
+ ```Python
45
+ text()
46
+ ```
47
+ 推測が正しいか[公式ドキュメント](http://docs.python-requests.org/en/master/user/quickstart/#response-content)で確認します。
48
+ ```Python
49
+ r.text
50
+ ```
51
+ と括弧なしで記載されています。よって括弧をはずして以下のように。
52
+
53
+ ```Python
54
+ html = r.text
55
+ ```

3

リンク先を変更

2018/08/09 02:18

投稿

umyu
umyu

スコア5846

answer CHANGED
@@ -5,7 +5,7 @@
5
5
  `BeautifulSoup`のバージョンが3.2.1なので`pip install BeautifulSoup`と入力してインストールしませんでしたか?
6
6
 
7
7
  案としては2つ
8
- 案1,[BeautifulSoup 3.2.1](https://www.crummy.com/software/BeautifulSoup/bs3/documentation.html#Parsing%20a%20Document)のドキュメントを参考にプログラムを修正する。
8
+ 案1,[BeautifulSoup 3.2.1](https://www.crummy.com/software/BeautifulSoup/bs3/documentation.html)のドキュメントを参考にプログラムを修正する。
9
9
 
10
10
  案2, BeautifulSoup(3.2.1)をアンインストール後にbeautifulsoup4をインストールする。
11
11
  2-1,BeautifulSoupをpip uninstallする。

2

追記

2018/08/08 15:04

投稿

umyu
umyu

スコア5846

answer CHANGED
@@ -1,9 +1,7 @@
1
- > BeautifulSoup (3.2.1)
1
+ > BeautifulSoup (3.2.1)と出たので「ではbsとBeautifulSoupに3をつけてみよう」
2
2
 
3
- >はbsとBeautifulSoupに3をつけてみよう
3
+ こういう時は公式ドキュメントを探します。キーワードは「BeautifulSoup doc 3.2.1」す、検索する[BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/)のページがHITします。
4
4
 
5
- まずこういう時は公式ドキュメントを探します。キーワードは「BeautifulSoup doc 3.2.1」です、検索すると[BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/)のページがHITします。
6
-
7
5
  `BeautifulSoup`のバージョンが3.2.1なので`pip install BeautifulSoup`と入力してインストールしませんでしたか?
8
6
 
9
7
  案としては2つ

1

追記

2018/08/08 15:02

投稿

umyu
umyu

スコア5846

answer CHANGED
@@ -16,6 +16,6 @@
16
16
  ```
17
17
  2-2, beautifulsoup4をインストールする。
18
18
  ```
19
- `pip install beautifulsoup4`
19
+ pip install beautifulsoup4
20
20
  ```
21
21
  としてくださいな。