Соскобление medium.com URL через Cheerio - PullRequest
0 голосов
/ 17 февраля 2019

Я пытаюсь удалить все URL с домашней страницы medium.com и сохранить их в массиве ссылок.Затем я пытаюсь открыть какой-либо конкретный URL-адрес и снова повторяю тот же шаг, но я не получаю никакого вывода в console.log (value) Часть после 'correct = $ ('. Section-content> .section-inner> a ')', кажется, не работает, потому что я попытался console.log до и после него, и это, кажется, работает, но я не получаю никакого вывода для значения.

const cheerio = require('cheerio');
const puppeteer = require('puppeteer');
const rp = require('request-promise');
const url = 'https://medium.com/';
const fs = require('fs');
const links = [];
const internalLinks = [];
const requestPromises = [];

puppeteer.launch().then(function(browser) {
    return browser.newPage();
}).then(function(page) {
    return page.goto(url).then(function() {
        return page.content();
    })
}).then(function(html) {
       $ = cheerio.load(html);
       check = $('article > .extremeHero-post > a');
       check2 = $('li > div > a'); //jquery get all hyperlinks
    $(check).each(function(i, value){
        var link = $(value).attr('href');
        links.push({"link":link});
    });
    $(check2).each(function(i,value) {
        var link = $(value).attr('href');
        links.push({"link":link});
    });
    const requestOptions = {
        uri:links[0].link,
        method:'GET',
        json:true
    }
    requestPromises.push(rp(requestOptions));
        puppeteer.launch().then(function(browser) {
            return browser.newPage();
        }).then(function(page) {
            return page.goto(requestOptions.uri).then(function() {
                return page.content();
            })
        }).then(function(html) {
            $ = cheerio.load(html);
            correct = $('.section-content > .section-inner > a');
            $(correct).each(function(i,value) {
                console.log(value);
            })
        console.log(internalLinks);
    }).catch(function(err) {
        console.log(err);
    })
}).catch(function(err) {
console.log(err);

})

...