How to request data of images from website Baidu Image by code to node js
Libs Introduction
- 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
- url - Where you want to go and which will decide what you will be responsed.
- method - It is just like tools we use as usual and, to a certain extent, will impact the result at last.
- params - It has a great influence on the web page as well as the data we get.
- 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
- word - What you want
- pn - When you start, which page you want
- 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.