回答編集履歴

2

追記

2018/04/30 15:01

投稿

quickquip
quickquip

スコア11038

test CHANGED
@@ -49,3 +49,17 @@
49
49
  ```
50
50
 
51
51
  こうかな?
52
+
53
+
54
+
55
+ ----
56
+
57
+ 何を直したのかわかっていないようなので。
58
+
59
+
60
+
61
+ せっかく要素を探索してループを回しているのに、その中で`//`から探索したら、常にルートノードから探索してしまって意味がないので、コンテキストノードの下を探すように書きました。
62
+
63
+
64
+
65
+ [http://www.techscore.com/tech/XML/XPath/xpath02.html/](http://www.techscore.com/tech/XML/XPath/xpath02.html/)

1

追記

2018/04/30 15:01

投稿

quickquip
quickquip

スコア11038

test CHANGED
@@ -23,3 +23,29 @@
23
23
 
24
24
 
25
25
  [https://docs.python.jp/3/reference/expressions.html#yieldexpr](https://docs.python.jp/3/reference/expressions.html#yieldexpr)
26
+
27
+
28
+
29
+ ----
30
+
31
+ ```
32
+
33
+ for result in info.xpath('//div[@class="syuroku_raiten_area"]/div[@class="hall_info"]'):
34
+
35
+ content = result.xpath('//div[@class="text"]/div[@class="bangumi"]/text()').extract_first()
36
+
37
+ ```
38
+
39
+
40
+
41
+ ```
42
+
43
+ for result in info.xpath('.//div[@class="hall_info"]'):
44
+
45
+ content = result.xpath('./div[@class="text"]/div[@class="bangumi"]/text()').extract_first()
46
+
47
+ (あとは略)
48
+
49
+ ```
50
+
51
+ こうかな?