質問編集履歴
7
サンプルコードの改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,7 +50,7 @@
|
|
50
50
|
|
51
51
|
<td>
|
52
52
|
|
53
|
-
<img src="../../media/test
|
53
|
+
<img src="../../media/test3.gif">
|
54
54
|
|
55
55
|
</td>
|
56
56
|
|
6
タグ追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
5
誤字訂正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Python, Scrapyでtd内の複数要素を抽出したい
|
test
CHANGED
File without changes
|
4
コード修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Python, Scrapyでtd内の複数要素を抽出したい
|
1
|
+
1Python, Scrapyでtd内の複数要素を抽出したい
|
test
CHANGED
@@ -74,9 +74,9 @@
|
|
74
74
|
|
75
75
|
item = TutorialItem()
|
76
76
|
|
77
|
-
item['time'] = table_row.xpath('td[
|
77
|
+
item['time'] = table_row.xpath('td[1]/text()').extract_first()
|
78
78
|
|
79
|
-
item['note'] = table_row.xpath('td[
|
79
|
+
item['note'] = table_row.xpath('td[3]/img/@src').extract_first()
|
80
80
|
|
81
81
|
yield item
|
82
82
|
|
3
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,13 +4,17 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
その際、複数のimgがtd内にある場合、下のScrapyコードでは、HTML上「◯」のimg srcは抽出できるのですが、「★」の値が抽出できません。
|
7
|
+
その際、複数のimgがtd内にある場合、下のScrapyコードでは、**HTML上「◯」のimg srcは抽出できるのですが、「★」の値が抽出できません。**
|
8
8
|
|
9
9
|
|
10
10
|
|
11
11
|
###■質問
|
12
12
|
|
13
13
|
HTML上の「◯」「★」両方の値を、テーブル構造(行,列)を保ちながらcsvとして出力できるScrapyコード(XPathの指定方法)を教えていただけますでしょうか。
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
なんとなくですが、extract_first()の部分をうまく修正すれば2つ目のimg srcの値「★」も抽出できるのではないかと想像しています。
|
14
18
|
|
15
19
|
|
16
20
|
|
2
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -72,7 +72,7 @@
|
|
72
72
|
|
73
73
|
item['time'] = table_row.xpath('td[0]/text()').extract_first()
|
74
74
|
|
75
|
-
item['note'] = table_row.xpath('td[
|
75
|
+
item['note'] = table_row.xpath('td[2]/img/@src').extract_first()
|
76
76
|
|
77
77
|
yield item
|
78
78
|
|
1
コードを簡略化
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,11 +24,17 @@
|
|
24
24
|
|
25
25
|
<tr>
|
26
26
|
|
27
|
-
<td>A
|
27
|
+
<td>A3</td>
|
28
28
|
|
29
|
-
<td>B
|
29
|
+
<td>B3</td>
|
30
30
|
|
31
|
+
<td>
|
32
|
+
|
33
|
+
<img src="../../media/test1.gif"> <!-- ◯ -->
|
34
|
+
|
35
|
+
<img src="../../media/test2.gif"> <!-- ★ -->
|
36
|
+
|
31
|
-
<
|
37
|
+
</td>
|
32
38
|
|
33
39
|
</tr>
|
34
40
|
|
@@ -44,23 +50,7 @@
|
|
44
50
|
|
45
51
|
</td>
|
46
52
|
|
47
|
-
<tr>
|
48
|
-
|
49
|
-
<td>A3</td>
|
50
|
-
|
51
|
-
<td>B3</td>
|
52
|
-
|
53
|
-
<td>
|
54
|
-
|
55
|
-
<img src="../../media/test1.gif"> <!-- ◯ -->
|
56
|
-
|
57
|
-
<img src="../../media/test2.gif"> <!-- ★ -->
|
58
|
-
|
59
|
-
</td>
|
60
|
-
|
61
|
-
</tr>
|
53
|
+
</tr>
|
62
|
-
|
63
|
-
</tr>
|
64
54
|
|
65
55
|
</tbody>
|
66
56
|
|