Baidu Image Search Basic Crawl Robot By Axios

How to request data of images from website Baidu Image by code to node js

Libs Introduction

  1. axios

Code Exhibition

const axios = require('axios')

var word = 'rem',
    sta = 0,
    num = 5

axios({
    url: 'https://image.baidu.com/search/acjson',
    method: 'get',
    params: {
        'tn': 'resultjson_com',
        'ipn': 'rj',
        'word': word,
        'pn': sta,
        'rn': num
    },
    headers: {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0'
    }
})
.then(function (res) {
    console.log(res.data)
})
.catch(function (error) {
    console.log(error)
});

Code Explaination

  1. url - Where you want to go and which will decide what you will be responsed.
  2. method - It is just like tools we use as usual and, to a certain extent, will impact the result at last.
  3. params - It has a great influence on the web page as well as the data we get.
  4. headers - It is said that when we pay a visit to one page, we need some stuff to identify who we are and they will make a decision about whether to give us access to it.

Params

  1. word - What you want
  2. pn - When you start, which page you want
  3. num - The number of images' data

Origin Url

Please parse the original page, and pay attention to finding the file that is used to encode the original url we receive.

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容