1. const puppeteer = require("puppeteer");
    2. const url = "http://www.kuwo.cn/search/list?key=你";
    3. const cheerio = require("cheerio");
    4. (async () => {
    5. const browser = await puppeteer.launch({
    6. headless: false, //模拟浏览器行为
    7. defaultViewport: null, //可视区域最大化
    8. args: ['--start-maximized'] //浏览器窗口最大化
    9. });
    10. const page = await browser.newPage();
    11. await page.goto(url)
    12. await autoScroll(page)
    13. await page.waitForTimeout(5000)
    14. var content = await page.content();
    15. var $ = cheerio.load(content,{
    16. decodeEntities:false
    17. })
    18. var items = $(".song_item");
    19. var arr = [];
    20. items.each((idex,ele)=>{
    21. var imgUrl = $(ele).find(".cover").attr("src");
    22. arr.push({
    23. imgUrl
    24. })
    25. })
    26. console.log(arr)
    27. })();
    28. function autoScroll(page) {
    29. page.evaluate(()=>{
    30. let distance = 250;
    31. function go() {
    32. setTimeout(() => {
    33. var scrollHeight = document.body.clientHeight;
    34. window.scrollTo(0, distance);
    35. distance += 50;
    36. console.log(distance)
    37. if (distance < scrollHeight) {
    38. go()
    39. }
    40. }, 100)
    41. }
    42. go()
    43. })
    44. }