const puppeteer = require("puppeteer");
const url = "http://www.kuwo.cn/search/list?key=你";
const cheerio = require("cheerio");
(async () => {
const browser = await puppeteer.launch({
headless: false, //模拟浏览器行为
defaultViewport: null, //可视区域最大化
args: ['--start-maximized'] //浏览器窗口最大化
});
const page = await browser.newPage();
await page.goto(url)
await autoScroll(page)
await page.waitForTimeout(5000)
var content = await page.content();
var $ = cheerio.load(content,{
decodeEntities:false
})
var items = $(".song_item");
var arr = [];
items.each((idex,ele)=>{
var imgUrl = $(ele).find(".cover").attr("src");
arr.push({
imgUrl
})
})
console.log(arr)
})();
function autoScroll(page) {
page.evaluate(()=>{
let distance = 250;
function go() {
setTimeout(() => {
var scrollHeight = document.body.clientHeight;
window.scrollTo(0, distance);
distance += 50;
console.log(distance)
if (distance < scrollHeight) {
go()
}
}, 100)
}
go()
})
}