質問編集履歴

3

タイトルの変更

2019/04/03 01:02

投稿

Otoro
Otoro

スコア36

test CHANGED
@@ -1 +1 @@
1
- PythonのScrapyのクローリング(スクレピング)でつまづます(汗)
1
+ Scrapy(スダー)でのfor文で何をキーにループをすればいいのかがわからない。
test CHANGED
File without changes

2

文法を修正

2019/04/03 01:02

投稿

Otoro
Otoro

スコア36

test CHANGED
File without changes
test CHANGED
@@ -92,31 +92,17 @@
92
92
 
93
93
  ```ここに言語を入力
94
94
 
95
- for res in response.xpath('//*[@id="content"]/div/section/div'):
95
+ for jobs in response.css(''):
96
96
 
97
97
  item = PyjobItem()
98
98
 
99
+ item['title'] = jobs.css('').extract_first()
99
100
 
101
+ item['company'] = jobs.css('').extract_first()
100
102
 
101
- job['title'] = res.xpath('//*[@id="content"]/div/section/div/ol/li[1]/h2/span[1]/a').extract()
102
-
103
- job['company'] = res.xpath('//*[@id="content"]/div/section/div/ol/li[1]/h2/span[1]/text()').extract()
104
-
105
- job['location'] = res.xpath('//*[@id="content"]/div/section/div/ol/li/h2/span[2]/a').extract()
103
+ item['location'] = jobs.css('').extract_first()
106
104
 
107
105
  yield item
108
-
109
-
110
-
111
- next_page = response.css('li.next a::attr(href)').extract()
112
-
113
-
114
-
115
- if next_page is not None:
116
-
117
- next_page = response.urljoin(next_page)
118
-
119
- yield scrapy.Request(next_page, callback=self.parse)
120
106
 
121
107
  ```
122
108
 

1

文法修正

2019/04/02 16:52

投稿

Otoro
Otoro

スコア36

test CHANGED
File without changes
test CHANGED
@@ -122,15 +122,31 @@
122
122
 
123
123
 
124
124
 
125
- 一番上タし抽出できない
125
+ for文プ処理をどうやって書けばいいのが苦戦中
126
-
126
+
127
+
128
+
127
- scrapyで次のペジへ遷移しスクレイピングしたいが、書き方がよくわからない。
129
+ 要は、何をキにループをすればいのかがわからない。
130
+
131
+
132
+
128
-
133
+ ・「NEXT」ページにもデータがあるので、それも最後まで取得したい。
134
+
135
+
136
+
129
- ・「社名」を抽出する際、改行スペースなどが入っていて、文字列だけを抽出する方法がわからない。
137
+ ・「社名」を抽出する際、以下のような\n\tなどが入っていて、文字列だけを抽出する方法がわからない。
138
+
139
+
140
+
130
-
141
+ ```ここに言語を入力
142
+
131
- ・調べれば調べるほどよくわからなくなる。
143
+ ['\n ',
144
+
132
-
145
+ '\n \n ',
146
+
133
-
147
+ '\n\t\t Stiftelsen Flowminder\n ']
148
+
149
+ ```
134
150
 
135
151
 
136
152
 
@@ -152,7 +168,25 @@
152
168
 
153
169
  [
154
170
 
171
+ {
172
+
173
+ "title": "Senior Python Developer",
174
+
175
+ "company": "Stiftelsen Flowminder",
176
+
177
+ "location": "Southampton, Hampshire, United Kingdom"
178
+
179
+ },
180
+
181
+ {
182
+
155
- {"title": "Senior Software Engineer (BACKEND)", "company": "CB Insights", "location": "New York, New York, USA"},
183
+ "title": "Senior Software Engineer (BACKEND)",
184
+
185
+ "company": "CB Insights",
186
+
187
+ "location": "New York, New York, USA"
188
+
189
+ },
156
190
 
157
191
 
158
192