質問編集履歴
1
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,17 +1,36 @@
|
|
1
|
-
以下のコード
|
1
|
+
以下の流れでコードを実行していて、以下のところでラーが出てしまいました。
|
2
|
-
|
2
|
+
どのように解決すればよろしいでしょうか。ご教授お願い致します。
|
3
|
-
ご指摘ご教授お願い致します。
|
4
3
|
|
5
4
|
```python
|
5
|
+
import requests
|
6
|
+
from bs4 import BeautifulSoup
|
7
|
+
↓
|
8
|
+
url = 'https://scraping-for-beginner.herokuapp.com/udemy'
|
9
|
+
res = requests.get(url)
|
10
|
+
↓
|
11
|
+
res
|
12
|
+
↓
|
13
|
+
soup =BeautifulSoup(res.text, 'html.parser')
|
14
|
+
soup
|
15
|
+
↓
|
16
|
+
subscribers = soup.find_all('p', attrs={'class': 'subscribers'})[0]
|
17
|
+
subscribers
|
18
|
+
↓
|
19
|
+
subscribers.text.split(':')
|
20
|
+
↓
|
6
21
|
n_subscribers = int(n_subscribers.text.split(':'))
|
7
22
|
n_subscribers
|
23
|
+
```
|
24
|
+
|
25
|
+
エラーコード
|
26
|
+
```python
|
27
|
+
n_subscribers = int(n_subscribers.text.split(':'))
|
28
|
+
n_subscribers
|
8
29
|
↓
|
9
|
-
--------------------------------------------------------------------------
|
10
30
|
NameError Traceback (most recent call last)
|
11
31
|
<ipython-input-59-0d30ba681ad2> in <module>
|
12
32
|
----> 1 n_subscribers = int(n_subscribers.text.split(':'))
|
13
33
|
2 n_subscribers
|
14
34
|
|
15
35
|
NameError: name 'n_subscribers' is not defined
|
16
|
-
|
17
36
|
```
|