* 首页分类解析,筛选暂未实现 * @param homeObj 首页传参对象 * @returns {string}
(homeObj)
| 1196 | * @returns {string} |
| 1197 | */ |
| 1198 | function homeParse(homeObj) { |
| 1199 | fetch_params = JSON.parse(JSON.stringify(rule_fetch_params)); |
| 1200 | let classes = []; |
| 1201 | if (homeObj.class_name && homeObj.class_url) { |
| 1202 | let names = homeObj.class_name.split('&'); |
| 1203 | let urls = homeObj.class_url.split('&'); |
| 1204 | let cnt = Math.min(names.length, urls.length); |
| 1205 | for (let i = 0; i < cnt; i++) { |
| 1206 | classes.push({ |
| 1207 | 'type_id': urls[i], |
| 1208 | 'type_name': names[i] |
| 1209 | }); |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | if (homeObj.class_parse) { |
| 1214 | let p = homeObj.class_parse.split(';'); |
| 1215 | let _ps = parseTags.getParse(p[0]); |
| 1216 | _pdfa = _ps.pdfa; |
| 1217 | _pdfh = _ps.pdfh; |
| 1218 | _pd = _ps.pd; |
| 1219 | MY_URL = rule.url; |
| 1220 | if (p.length >= 3) { // 可以不写正则 |
| 1221 | try { |
| 1222 | let html = getHtml(homeObj.MY_URL); |
| 1223 | if (html) { |
| 1224 | homeHtmlCache = html; |
| 1225 | let list = _pdfa(html, p[0]); |
| 1226 | if (list && list.length > 0) { |
| 1227 | list.forEach((it,idex) => { |
| 1228 | try { |
| 1229 | let name = _pdfh(it, p[1]); |
| 1230 | if (homeObj.cate_exclude && (new RegExp(homeObj.cate_exclude).test(name))) { |
| 1231 | return; |
| 1232 | } |
| 1233 | // let url = pdfh(it, p[2]); |
| 1234 | let url = _pd(it, p[2]); |
| 1235 | if (p.length > 3 && p[3]) { |
| 1236 | let exp = new RegExp(p[3]); |
| 1237 | url = url.match(exp)[1]; |
| 1238 | } |
| 1239 | |
| 1240 | classes.push({ |
| 1241 | 'type_id': url.trim(), |
| 1242 | 'type_name': name.trim() |
| 1243 | }); |
| 1244 | } catch (e) { |
| 1245 | console.log(`分类列表定位第${idex}个元素正常报错:${e.message}`); |
| 1246 | } |
| 1247 | }); |
| 1248 | } |
| 1249 | } |
| 1250 | } catch (e) { |
| 1251 | console.log(e.message); |
| 1252 | } |
| 1253 | |
| 1254 | } |
| 1255 | } |