-
Notifications
You must be signed in to change notification settings - Fork 18
/
cian.js
362 lines (319 loc) · 11.6 KB
/
cian.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/*
cian.js - sobnik.chrome module to work with cian.ru
Copyright (c) 2014 Pavel Mozhchil <[email protected]>
Copyright other contributors as noted in the AUTHORS file.
This file is part of sobnik.chrome, Sobnik plugin for Chrome:
http://sobnik.com.
This is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at
your option) any later version.
This software is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program. If not, see
<http://www.gnu.org/licenses/>.
*/
;(function () {
console.log ("Loading cian");
var sobnik = window.sobnik;
console.assert (sobnik, "Sobnik required");
var cmn = sobnik.require ("cmn");
var boards = sobnik.require ("boards");
var types = "flat|suburban|commercial";
var cian = {
name: "cian.ru",
// FIXME add abuse reasons
urls: [
"http[s]?://www.cian.ru/rent/("+types+")/\\d+/($|#.*|\\?.*)",
"http[s]?://www.cian.ru/sale/("+types+")/\\d+/($|#.*|\\?.*)",
],
trigger: "span.object_descr_phones_row",
untrigger: [
"span.object_descr_warning:contains(\"снято\")"
],
/* capture: {
photoImage: {
selector: "div.object_descr_images div.object_descr_images_w a img",
attr: "src"
}
},
*/
list: {
// the row in the list
rowSelector: "table.cat tr[id^='tr_']",
// container for the link to an ad (relative to rowSelector)
hrefSelector: "td[id$='comment'] div a[target='_blank']",
// links matching this pattern will be marked in the list
pattern: ".*("+types+").*",
// matching urls will be treated as a list of ads
urls: [
"http[s]?://www.cian.ru/cat.php"
],
mark: function (row, ad) {
var html = "<span style='display:block;"
+"float:left; margin:4px 0 0 0; padding: 0'>"
+boards.marker (ad)+"</span>";
$(row).find("td:eq(0)").prepend (html);
return $(row).find("td:eq(0) span")[0];
},
},
page: {
marks: [
{
selector: "h1.object_descr_addr",
mark: function (parent, ad) {
var html = "<span style='display:block;"
+"float:left; margin:7px 0 0 -12px; padding: 0'>"
+boards.marker (ad)+"</span>";
$(parent).prepend (html);
return $(parent).find("span")[0];
},
},
{
selector: "span.object_descr_phones_row",
mark: function (parent, ad) {
var html = "<span style='display:block;"
+"float:left; margin:10px 0 0 0; padding: 0'>"
+boards.marker (ad)+"</span>";
$(parent).prepend (html);
return $(parent).find("span")[0];
},
},
],
},
url2id: function (url) {
var id = url.match ("/(\\d+)/($|#.*|\\?.*)");
// console.log ("Url "+url);
// console.log (id);
if (!id)
return "";
return "cian:"+id[1];
},
fields: {
name: {
selector: "span.object_descr_realtor_name",
data: {
name: {},
},
},
photo: {
selector: "div.object_descr_images div.object_descr_images_w a",
attr: "href",
data: {
photo: {},
}
},
city: {
selector: "h1.object_descr_addr",
data: {
city: {
rx: "([^,]+)(,|$)",
rxi: 1
}
}
},
street: {
selector: "h1.object_descr_addr",
data: {
street: {
rx: "[^,]+,\\s+(.+)",
rxi: 1
},
}
},
// FIXME check cities w/o metro
district: {
selector: "div.object_descr_metro",
data: {
district: {
rx: "([^\\d]+)\\s?($|\\d+)",
rxi: 1
},
}
},
daily: {
selector: "div.object_descr_title",
data: {
daily: {
rx: "посуточно",
conv: function (s) {
return s ? "daily" : "";
},
}
},
},
type: {
selector: "td.header_menu_item_selected div.header_menu_item_w",
data: {
type: {
conv: function (s) {
if (s.indexOf ("Аренда") == 0) return "sdam";
if (s.indexOf ("Продажа") == 0) return "prodam";
return "unknown";
},
}
},
},
rooms: {
selector: "div.object_descr_title",
data: {
rooms: {
rx: "(\\d+)-\\D+",
rxi: 1
},
},
},
area: {
selector: "table.object_descr_props tr td",
data: {
area: {
rx: "(\\d+)\\s+м²",
rxi: 1
},
floor: {
rx: "(\\d+)/(\\d+)",
rxi: 1
},
floors: {
rx: "(\\d+)/(\\d+)",
rxi: 2
}
}
},
price: {
selector: "#price_rur",
data: {
price: {}
}
},
notes: {
selector: "div.object_descr_text",
data: {
notes: {
rx: "([\\s\\S]*)Телефоны:",
rxi: 1,
},
},
},
author_named: {
selector: "span.object_descr_realtor_name",
data: {
author: {
conv: function (s) {
if (!s.match ("ID:"))
return "agent";
}
}
}
},
author_age: {
selector: "span.object_descr_realtor_checked_text",
data: {
author: {
conv: function (s) {
if (!s.match ("Новый пользователь"))
return "agent";
}
}
}
},
commission: {
selector: "span.object_descr_td_l",
data: {
author: {
conv: function (s) {
if (!s.match ("комиссия 0%"))
return "agent";
}
}
}
},
user_id: {
selector: "span.object_descr_realtor_name_editable input",
attr: "value",
data: {
user_id: {}
}
},
phone: {
selector: "strong.object_descr_phone_orig a",
attr: "href",
data: {
// FIXME check format of phone
phone: {
rx: "tel:(.*)",
rxi: 1,
conv: function (s) {
return s
.replace (/-/g, "")
.replace (/\s/g, "");
}
},
phoneOff: {
rx: "tel:(.*)",
rxi: 1,
conv: function (s) {
return s
.replace (/-/g, "")
.replace (/\s/g, "");
}
}
}
},
lat: {
selector: "div.object_descr_map_static input",
attr: "value",
data: {
lat: {
rx: ".*&pt=(\\d+.\\d+),(\\d+.\\d+),flag",
rxi: 2
}
}
},
lon: {
selector: "div.object_descr_map_static input",
attr: "value",
data: {
lon: {
rx: ".*&pt=(\\d+.\\d+),(\\d+.\\d+),flag",
rxi: 1
}
}
},
date: {
selector: "span.object_descr_dt_added",
data: {
created: {
conv: function (s) {
var today = new Date ();
var yesterday = new Date (today);
yesterday.setDate (today.getDate () - 1);
return boards.dateFmt (
s.replace ("сегодня", boards.dts (today))
.replace ("вчера", boards.dts (yesterday))
.replace (" января", ".01.2014")
.replace (" февраля", ".02.2014")
.replace (" марта", ".03.2014")
.replace (" апреля", ".04.2014")
.replace (" мая", ".05.2014")
.replace (" июня", ".06.2014")
.replace (" июля", ".07.2014")
.replace (" августа", ".08.2014")
.replace (" сентября", ".09.2014")
.replace (" октября", ".10.2014")
.replace (" ноября", ".11.2014")
.replace (" декабря", ".12.2014")
.replace (", ", " ")
);
}
}
}
}
}
};
window.sobnik.boards.cian = cian;
window.sobnik.boards.current = cian;
} ());