Node.js爬取百度图片之解析objURL外加随手写个瀑布流

分析请求地址

先来分析一下请求地址,我搜索的是“古力娜扎”

https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=&fp=result&queryWord=%E5%8F%A4%E5%8A%9B%E5%A8%9C%E6%89%8E&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=&z=9&ic=&hd=&latest=©right=&word=%E5%8F%A4%E5%8A%9B%E5%A8%9C%E6%89%8E&s=&se=&tab=&width=0&height=0&face=&istype=&qc=&nc=&fr=&expermode=&force=&pn=0&rn=30&gsm=&1571040360801=

queryWord:表示要查询的关键字

word:也表示要查询的关键字

hd:表示高清

pn:表示第几页,首页为0

rn:表示每页显示的图片数量

随便自定义

 

二话不说,开爬

const https = require('https');

let options = {
    hostname: 'image.baidu.com',
    path: '/search/acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=&fp=result&queryWord=%E5%8F%A4%E5%8A%9B%E5%A8%9C%E6%89%8E&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=&z=9&ic=&hd=&latest=&copyright=&word=%E5%8F%A4%E5%8A%9B%E5%A8%9C%E6%89%8E&s=&se=&tab=&width=0&height=0&face=&istype=&qc=&nc=&fr=&expermode=&force=&pn=0&rn=30&gsm=&1571040360801=',
    headers: {  //伪装身份
        "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36",
        "Referer": "https://image.baidu.com/"
    }    
}

let req = https.request(options, res => {
    let chucks = [];
    res.on('data', chuck => {
        chucks.push(chuck);
    })
    res.on('end', () => {
        let result = Buffer.concat(chucks).toString();
        console.log(JSON.parse(result));  //看看拿到的数据,分析一通
    })
})

req.on('error', err => {
    console.log(err);
})
req.end();

拿到的每一条数据大概长这样

 

thumbURL、middleURL、hoverURL都是一些百度站内显示的图片地址,但真实的原图地址信息保存在

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值