質問編集履歴

1

コードをMarkdown方式に修正しました。

2020/07/19 14:30

投稿

Shu0101
Shu0101

スコア14

test CHANGED
File without changes
test CHANGED
@@ -4,13 +4,55 @@
4
4
 
5
5
 
6
6
 
7
- 例えば、ヨタ自動車のPBRを取り出したいとします。
7
+ 以下の証券サイが対象です。
8
8
 
9
- view-source:https://kabutan.jp/stock/?code=7203
9
+ ```html
10
10
 
11
- 上記のソース(株探.jp)の382行目にある数字を取り出すには、
11
+ <div id="stockinfo_i3">
12
12
 
13
+ <table>
14
+
15
+ <thead>
16
+
17
+ <tr>
18
+
19
+ <th scope='col'><abbr title="Price Earnings Ratio">PER</abbr></th>
20
+
21
+ <th scope='col'><abbr title="Price Book-value Ratio">PBR</abbr></th>
22
+
23
+ <th scope='col'>利回り</th>
24
+
25
+ <th scope='col'>信用倍率</th>
26
+
27
+ </tr>
28
+
29
+ </thead>
30
+
31
+ <tbody>
32
+
33
+ <tr>
34
+
35
+ <td>-<span>倍</span></td>
36
+
37
+ <td>0.95<span>倍</span></td>
38
+
39
+ <td>-<span>%</span></td>
40
+
41
+ <td>1.75<span>倍</span></td>
42
+
43
+ </tr>
44
+
45
+ <tr>
46
+
47
+ ```
48
+
49
+ 上記のhtmlソースの後半にある「1.75」という取り出すには、
50
+
51
+ ```python
52
+
13
- '#stockinfo_i3 > table > tr:nth-child(2) > td:nth-child(2)’
53
+ q.find('#stockinfo_i3 > table > tr:nth-child(2) > td:nth-child(4)’).text()
54
+
55
+ ```
14
56
 
15
57
  で良いと考えたのですが、うまく行きません。
16
58