data.symbol不支持值

问题描述 投票:0回答:1

我想把存储在符号中的数据,让木偶人在搜索栏中用 scrapePage.type. 我没有收到任何错误信息,但代码的作用是,如果data.symbol没有持有任何值,即使它是,因为当它发送嵌入消息,符号的.addField用 data.symbol 来发送消息。

try { // Alpha AI Scrape
    scrapePage.goto('https://app.flowalgo.com/');
    await scrapePage.waitForSelector('#alphaAI-v1', {timeout: 10000});
    await scrapePage.addScriptTag({url: 'https://code.jquery.com/jquery-3.4.0.min.js'});


    let data = await scrapePage.evaluate((darkFlowData) => {
        let $ = window.$;
        let data = [];

        // Scrape Ratings
        $('#fa_aai > div.alpha-ai-signals.animated.fadeIn').each(function() {
            let symbol = $('div:nth-child(1) > div.symbol > span').text().trim();

            ticker = symbol;

            if (darkFlowData.lastAlphaAIIDs.includes(symbol)) return;


            let date = $('div:nth-child(1) > div.date > span').text().trim();
            let reference = $('div:nth-child(1) > div:nth-child(3)').text().trim();
            let signal = $('div:nth-child(1) > div.sentiment').text().trim();


            data.push({symbol, date, reference, signal});

        }); // Scrape Ratings



        return data;
    }, darkFlowData);



    await scrapePage.waitForSelector('#filter-flow > div > input[type=text]', {timeout: 10000});
    await scrapePage.addScriptTag({url: 'https://code.jquery.com/jquery-3.4.0.min.js'});
    await scrapePage.type('#filter-flow > div > input[type=text]', data.symbol);



    let data1 = await scrapePage.evaluate((darkFlowData) =>{
        let $ =window.$;
        let data1 = [];

        //Scrape for Contracts
        $('#optionflow > div.component-body.ps.ps--theme_default.ps--active-y > div.data-body > div:nth-child(20)').each(function() {
            let symbol1 = $('#optionflow > div.component-body.ps.ps--theme_default.ps--active-y > div.data-body > div:nth-child(20) > div.ticker > span').text().trim();

            if (darkFlowData.lastAlphaAIIDs.includes(symbol1)) return;

            let exp = $('#optionflow > div.component-body.ps.ps--theme_default.ps--active-y > div.data-body > div:nth-child(20) > div.expiry > span').text().trim();
            let strike = $('#optionflow > div.component-body.ps.ps--theme_default.ps--active-y > div.data-body > div:nth-child(20) > div.strike > span').text().trim();
            let type = $('#optionflow > div.component-body.ps.ps--theme_default.ps--active-y > div.data-body > div:nth-child(20) > div.contract-type > span').text().trim();

            data1.push({symbol1, exp, strike, type});
        });

        return data1;
    }, darkFlowData);



    for (let entry of data) { // Output Ratings
        darkFlowData.lastAlphaAIIDs.push(entry.symbol);
        if (darkFlowData.lastAlphaAIIDs.length > 500) darkFlowData.lastAlphaAIIDs.shift();

        let color = config.colors.aai;


        let embed = new RichEmbed()
            .setColor(color)
            .setTitle('Alpha AI Alert')
            .addField('Symbol', entry.symbol, true)
            .addField('Contract Selection', entry.symbol)
            .addField('Expiration', entry.exp)
            .addField('Strike', entry.strike)
            .addField('Type', entry.type)
            .setTimestamp()



        for (let guild of clientGuilds) {
            if (typeof darkFlowData.guilds[guild.id].channels.alphaAI !== 'undefined') {
                client.channels.get(darkFlowData.guilds[guild.id].channels.alphaAI).send(embed);
            }
        }

        sendDMAlerts(entry.symbol.toLowerCase(), embed, null, 'alphaAI');
    }

    fs.writeFile(config.files.darkFlow, JSON.stringify(darkFlowData), err => {});
} catch (error) {
    console.log('ALPHA AI SCRAPE ERROR: ' + error);
}
javascript jquery node.js discord.js puppeteer
1个回答
1
投票

data 是一个对象数组。当你在循环中使用每个对象时,比如在 for (let entry of data) { ... addField('Contract Selection', entry.symbol)జజజజజజజజజజజజజజజజజజజజజజజజజజజజజజజజజజజజజజజ symbol 是有。但是 data 数组没有 .symbol 循环外的属性,它是 undefined. 它必须是这样的东西 data[0].symbol.

© www.soinside.com 2019 - 2024. All rights reserved.