質問編集履歴
1
コードをMarkdown方式に修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,10 +1,31 @@
|
|
1
1
|
こんにちは。
|
2
2
|
PyQueryを用いたスクレイピングでHTMLから情報を取り出す際の、場所指定について教えていただけませんでしょうか。
|
3
3
|
|
4
|
-
|
4
|
+
以下の証券サイトが対象です。
|
5
|
+
```html
|
6
|
+
<div id="stockinfo_i3">
|
7
|
+
<table>
|
8
|
+
<thead>
|
9
|
+
<tr>
|
10
|
+
<th scope='col'><abbr title="Price Earnings Ratio">PER</abbr></th>
|
11
|
+
<th scope='col'><abbr title="Price Book-value Ratio">PBR</abbr></th>
|
12
|
+
<th scope='col'>利回り</th>
|
13
|
+
<th scope='col'>信用倍率</th>
|
14
|
+
</tr>
|
15
|
+
</thead>
|
16
|
+
<tbody>
|
17
|
+
<tr>
|
5
|
-
|
18
|
+
<td>-<span>倍</span></td>
|
19
|
+
<td>0.95<span>倍</span></td>
|
20
|
+
<td>-<span>%</span></td>
|
21
|
+
<td>1.75<span>倍</span></td>
|
22
|
+
</tr>
|
23
|
+
<tr>
|
24
|
+
```
|
6
|
-
上記のソース
|
25
|
+
上記のhtmlソースの後半にある「1.75」という取り出すには、
|
26
|
+
```python
|
7
|
-
'#stockinfo_i3 > table > tr:nth-child(2) > td:nth-child(
|
27
|
+
q.find('#stockinfo_i3 > table > tr:nth-child(2) > td:nth-child(4)’).text()
|
28
|
+
```
|
8
29
|
で良いと考えたのですが、うまく行きません。
|
9
30
|
|
10
31
|
ご教示頂けるとありがたいです。
|