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.

你可能感兴趣的:(Baidu Image Search Basic Crawl Robot By Axios)