老司机开车记
来源:互联网 发布:数学必修三算法循环 编辑:程序博客网 时间:2024/04/28 10:21
node.js+jsdom 小爬虫 并不是框架>.<
解决某些个人问题:
利用了dfs搜索
"use strict";let https=require('https');let fs=require('fs');let path=require('path');let jsdom=require('jsdom');let visted=[];function isDir(url){ if(url.indexOf('.')!==-1){ return false; } try{ fs.mkdirSync(url); console.log('mkdir:'+url); }catch(e){ console.log(`IOerror:${e}`) } return true;}function isUrlVisited(url){ for(let i=0;i<visted.length;i++){ if(visted[i]===url){ return true; } } visted.push(url); return false;}function writeFile(url){ if(isDir(url)&&isUrlVisited(url)){ return; } let filePath=path.parse(url); try{ urltoFile(url); }catch(error){ console.log(error) }}function urltoFile(url){ https.request(root+url, (res)=>{ res.on('data',(data)=>{ fs.appendFileSync(url,data); }); }).on('error',(e)=>{ console.log(e); }).end();}function dealUrl(url){ isUrlVisited(url); isDir(url); writeFile(url);}let root='https://www.seryox.com';function applyUrl(url){ jsdom.env({ url: url, scripts: ["http://code.jquery.com/jquery.js"], done: function (err, window) { let $=window.$; console.log('done'); try{ let arr=$('a'); console.log(arr.length) for(let i=0;i<arr.length;i++){ let href=$(arr[i]).attr('href'); if(href.match(/^\/pic/)&&!isUrlVisited(href)){ console.log(href); if(isDir(href)){ console.log('dir:'+url+href); applyUrl(root+href); }else{ console.log('file:'+url+href); writeFile(href); } } } }catch(e){ console.log(e+'@'+url); } } });}applyUrl(root+'/');
生成的文件夹编码为UTF-8 URL编码
利用此文件可解决
"use strict";let fs=require('fs');let root='/pic';function isDir(url){ if(url.indexOf('.')!==-1){ return false; } return true;}function rename(path,name){ if(name.indexOf('%')!==-1) console.log(path+'/'+name+' to '+path+'/'+decodeURI(name)) fs.renameSync(path+'/'+name,path+'/'+decodeURI(name));}function main(path){ let fd=fs.readdirSync(path); for(let i=0;i<fd.length;i++){ if(isDir(fd[i])){ main(path+'/'+fd[i]); } rename(path,fd[i]); }}main(root);
0 0
- 老司机开车记
- 老司机开车
- 用Python开车的老司机
- Angularjs 入门 (老司机开车版)
- 老司机总结出的21条开车经验
- 老司机总结出的21条开车经验
- 新手必看一位老司机的十年开车经验
- 请系好安全带,Channel老司机开车啦! 2017-12-20 小奇爱音乐 奇亿音乐 老司机 带带我 我要去省城 不是所有的司机 都是老司机 更不是所有的老司机 都是开车的
- 小司机开车了
- 很宝贵!老司机总结出的21条开车经验
- 很宝贵!老司机总结出的21条开车经验
- C语言学习—第二章 C语言入门程序(老司机开车)
- 微商怎么做?看看月入破万的老司机们是如何开车的
- SVG 新司机开车指南
- 26条安全开车经验 开车20年老司机分享
- Django 老司机
- 老司机代码
- 老司机带新手
- 将字符串转换为整数
- CSU--1721: 皇家火枪手
- ContentProvider
- 请实现一个算法,确定一个字符串的所有字符是否全都不同。这里我们要求不允许使用额外的存储结构
- 用CInternetSession实现HTTP POST登录
- 老司机开车记
- Yarn源码分析之MRAppMaster上MapReduce作业处理总流程(一)
- dubbo入门实例代码
- 基础篇 _练习 小练习5~14
- 时间下拉框(2)
- Intent和Bundle传递数据
- ZOJ_3029_TreasureMap(DancingLinksX精确覆盖)
- Beyond Compare实用发布功能
- 两次点击退出