質問編集履歴
1
コード位置修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,68 +34,70 @@
|
|
34
34
|
|
35
35
|
```
|
36
36
|
|
37
|
+
|
38
|
+
|
39
|
+
```python3
|
40
|
+
|
41
|
+
#filename:scrapy_blog_spider2.py
|
42
|
+
|
43
|
+
# -*- coding: utf-8 -*-
|
44
|
+
|
45
|
+
import scrapy
|
46
|
+
|
47
|
+
from ten_min_scrapy.items import Post
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
class Post(scrapy.Spider):
|
52
|
+
|
53
|
+
name = 'scrapy_blog_spider2'
|
54
|
+
|
55
|
+
allowed_domains = ['data.ratp.fr/explore/']
|
56
|
+
|
57
|
+
start_urls = ['https://data.ratp.fr/explore/?sort=modified']
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
def parse(self, response):
|
66
|
+
|
67
|
+
"""
|
68
|
+
|
69
|
+
レスポンスに対するパース処理
|
70
|
+
|
71
|
+
"""
|
72
|
+
|
73
|
+
# response.css で scrapy デフォルトの css セレクタを利用できる
|
74
|
+
|
75
|
+
for post in response.css('.ods-catalog-card__body'):
|
76
|
+
|
77
|
+
# items に定義した Post のオブジェクトを生成して次の処理へ渡す
|
78
|
+
|
79
|
+
yield Post(
|
80
|
+
|
81
|
+
url=post.css('ods-catalog-card-title a::attr(href)').extract_first().strip(),
|
82
|
+
|
83
|
+
title=post.css('ods-catalog-card-title a::text').extract_first().strip(),
|
84
|
+
|
85
|
+
description=post.css('ods-catalog-card-description p::text').extract_first().strip(),
|
86
|
+
|
87
|
+
)
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
```
|
92
|
+
|
93
|
+
|
94
|
+
|
37
95
|
```
|
38
96
|
|
39
97
|
$ scrapy crawl scrapy_blog_spider2
|
40
98
|
|
41
99
|
```
|
42
100
|
|
43
|
-
```python3
|
44
|
-
|
45
|
-
#filename:scrapy_blog_spider2.py
|
46
|
-
|
47
|
-
# -*- coding: utf-8 -*-
|
48
|
-
|
49
|
-
import scrapy
|
50
|
-
|
51
|
-
from ten_min_scrapy.items import Post
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
class Post(scrapy.Spider):
|
56
|
-
|
57
|
-
name = 'scrapy_blog_spider2'
|
58
|
-
|
59
|
-
allowed_domains = ['data.ratp.fr/explore/']
|
60
|
-
|
61
|
-
start_urls = ['https://data.ratp.fr/explore/?sort=modified']
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
def parse(self, response):
|
70
|
-
|
71
|
-
"""
|
72
|
-
|
73
|
-
レスポンスに対するパース処理
|
74
|
-
|
75
|
-
"""
|
76
|
-
|
77
|
-
# response.css で scrapy デフォルトの css セレクタを利用できる
|
78
|
-
|
79
|
-
for post in response.css('.ods-catalog-card__body'):
|
80
|
-
|
81
|
-
# items に定義した Post のオブジェクトを生成して次の処理へ渡す
|
82
|
-
|
83
|
-
yield Post(
|
84
|
-
|
85
|
-
url=post.css('ods-catalog-card-title a::attr(href)').extract_first().strip(),
|
86
|
-
|
87
|
-
title=post.css('ods-catalog-card-title a::text').extract_first().strip(),
|
88
|
-
|
89
|
-
description=post.css('ods-catalog-card-description p::text').extract_first().strip(),
|
90
|
-
|
91
|
-
)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
```
|
96
|
-
|
97
|
-
|
98
|
-
|
99
101
|
|
100
102
|
|
101
103
|
|