node.js抓取网上图片保存到本地
用到两个模块,http和fs
var http = require("http");
var fs = require("fs");
var server = http.createServer(function(req, res){}).listen(50082);
console.log("http start");
var url = "http://s0.hao123img.com/res/img/logo/logonew.png";
http.get(url, function(res){
var imgData = "";
res.setEncoding("binary"); //一定要设置response的编码为binary否则会下载下来的图片打不开
res.on("data", function(chunk){
imgData+=chunk;
});
res.on("end", function(){
fs.writeFile("./public/upload/downImg/logonew.png", imgData, "binary", function(err){
if(err){
console.log("down fail");
}
console.log("down success");
});
});
});
node.js抓取网上图片保存到本地的更多相关文章
- Node.js 抓取电影天堂新上电影节目单及ftp链接
代码地址如下:http://www.demodashi.com/demo/12368.html 1 概述 本实例主要使用Node.js去抓取电影的节目单,方便大家使用下载. 2 node packag ...
- C#抓取网络图片保存到本地
C#抓取网络图片保存到本地 System.Net.WebClient myWebClient = new System.Net.WebClient(); //将头像保存到服务器 string virP ...
- node.js抓取数据(fake小爬虫)
在node.js中,有了 cheerio 模块.request 模块,抓取特定URL页面的数据已经非常方便. 一个简单的就如下 var request = require('request'); va ...
- Node.js抓取网页
前几天四六级成绩出来(然而我没考),用Node.js做了一个模拟表单提交并抓取数据的Web 总结一下用到的知识,简单的网页抓取大概就是这个流程了 发送Get或Post请求 表单提交,首先弄到原网页提交 ...
- 使用node.js抓取有路网图书信息(原创)
之前写过使用python抓取有路网图书信息,见http://www.cnblogs.com/dyf6372/p/3529703.html. 最近想学习一下Node.js,所以想试试手,比较一下http ...
- node.js 抓取网页数据
var $ = require('jquery'); var request = require('request'); request({ url: 'http:\\www.baidu.com',/ ...
- node.js 抓取
http://blog.csdn.net/youyudehexie/article/details/11910465 http://www.tuicool.com/articles/z2YbAr ht ...
- 爬虫:selenium + phantomjs 解决js抓取问题(一)
selenium模块主要用来做测试,模拟键盘.鼠标来操作浏览器. phantomjs 就像一个无界面的浏览器一样. 两个结合能很好的解决js抓取的问题. 测试代码: #coding=utf-8 fro ...
- node.js爬取数据并定时发送HTML邮件
node.js是前端程序员不可不学的一个框架,我们可以通过它来爬取数据.发送邮件.存取数据等等.下面我们通过koa2框架简单的只有一个小爬虫并使用定时任务来发送小邮件! 首先我们先来看一下效果图 差不 ...
随机推荐
- Visual Studio的 Apache Cordova 插件CTP3.0发布!
北京时间12号晚23点开始的Connect()活动上,微软发布了一系列激动人心的消息! .NET开源了!以后.NET将可在Linux和Mac OS平台上运行! VS免费了!!如果你是学生,个人开发者, ...
- poj 2367
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3658 Accepted: 2433 ...
- 【Python web自动化】之读取配置文件参数,利用cookie返回值进行跳过验证码进行登录操作
当进行Python的Web自动化时,会涉及到验证码问题,该如何跳过执行呢,下面请看代码: 1.首先新建配置文件*.ini格式 config.ini [db] #基础地址: baseurl = http ...
- Linux4_文件操作
以下操作都是在终端命令行: 1 apt-get install 应用名称,(---:apt-get是从Ubuntu的软件应用里自动下载) 如果你不知道下载,随便输入:java,javac,tree ...
- saltstack之服务管理
1.启动服务 /srv/salt/service/nfs.sls rpcbind: service.running: - enable: True #开机自动启动 # - enable: False ...
- LR报错 No buffer space available Try changing the registry value 端口号不够用了
报错:Action.c(6): Error -27796: Failed to connect to server "10.16.137.8:10035": [10055] No ...
- CentOS7.1安装 Vsftpd FTP 服务器
# yum install vsftpd 安装 Vsftpd FTP 编辑配置文件 ‘/etc/vsftpd/vsftpd.conf’ 用于保护 vsftpd. # vi /etc/vsftpd/vs ...
- maven filters 和 resource
1 filter 1.1 用途 对多个配置文件进行选择. 1.2 选择的依据 1.3 使用的方式 第一,在<resource>标签下面加<filtering>标签,并且< ...
- ElasticSearch(二十六)修改分词器及定制自己的分词器
1.默认的分词器 standard 分词器 standard tokenizer:以单词边界进行切分standard token filter:什么都不做lowercase token filter: ...
- Python锁
# coding:utf-8 import threading import time def test_xc(): f = open("test.txt","a&quo ...