拥有一个Path.DirectorySeparatorChar
这是我的代码(只是一个网络抓取测试)
RequestError: Error: Invalid URI "/"
当我使用const URLS = ['url1','url2']-可以,但是我想将发帖人另存为 const requestPromise = require('request-promise');
const cheerio = require('cheerio');
const fs = require('fs');
const request = require('request')
const URLS = [
{
url:'ur1',
id: 'venom'
},
{
url: 'url2',
id: 'black_pantera'
}
];
(async () => {
let moviesData=[];
for(let movie of URLS){
const response = await requestPromise({
uri: movie,
headers: {
'authority': 'www.imdb.com',
'method': 'GET',
'path': '/title/tt1270797/?ref_=vi_md_po',
'scheme': 'https',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7',
'cache-control': 'max-age=0',
'referer':'https//www.imdb.com/list/ls053181649/
videoplayer/vi2247868185ref_=hm_hp_i_1',
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'none',
'sec-fetch-user': '1',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36'
},
gzip: true
}
);
let $ = cheerio.load(response);
let title = $('div[class="title_wrapper"] > h1').text().trim();
let rating = $('span[itemprop="ratingValue"]').text();
let poster = $('div[class="poster"] > a > img').attr('src');
let dates = $('a[title="See more release dates"]').text();
let usersVoices = $('div[class="imdbRating"] > a > span').text().trim();
let genres =[];
$('div[class="title_wrapper"] a[href^="/search/title?genres="]').each((i, element) =>{
let genre = $(element).text();
genres.push(genre);
});
moviesData.push({
title,
poster,
genres,
rating,
usersVoices,
dates
});
}
})()
,然后将URLS转换为:
.jpg
仅在数组转换后才出现此错误
之后,我想使用 const URLS = [
{
url:'url1',
id: 'venom'
},
{
url: 'url2',
id: 'black_pantera'
}
];
此处显示完整的错误代码:[1]:https://i.stack.imgur.com/s38Zc.png
谢谢您的回答