3

I'm trying to get the reviews in aliexpress but for some reason wait() function always fail to find #transction-feedback

So technically if you go to that link and click Feedback tap it will show all the reviews

.click does work because it clicks the tab, but seems like #transction-feedback never shows up. I tried to recreate the same using the browser and #transction-feedback shows up.

enter image description here

Here's the code

const cheerio = require('cheerio')
const Nightmare = require('nightmare')
const nightmare = Nightmare({
    show: true
})


const URL = 'https://www.aliexpress.com/item/Samsung-Earphones-EHS64-Headsets-With-Built-in-Microphone-3-5mm-In-Ear-Wired-Earphone-For-Smartphones/32854052487.html?spm=2114.search0103.3.1.51dd26c3CxZ3zZ&ws_ab_test=searchweb0_0,searchweb201602_8_10065_10068_319_10059_10884_317_10887_10696_321_322_10084_453_10083_454_10103_10618_10307_537_536,searchweb201603_50,ppcSwitch_0&algo_expid=5587ff37-5e3a-45a8-8206-7b182433a961-0&algo_pvid=5587ff37-5e3a-45a8-8206-7b182433a961'

    nightmare
        .goto(URL)
        .click('li[data-trigger="feedback"]')
        .wait('#transction-feedback')
        .evaluate(() => {
            return document.body.innerHTML

        })
        .end()
        .then((result) => {
            const $ = cheerio.load(result)

            res.json($.html())

        })
        .catch(error => {
            console.error('Search failed:', error)
        })

I tried on Puppeteer as well but doesnt work

const puppeteer = require('puppeteer');
const URL = 'https://www.aliexpress.com/item/Samsung-Earphones-EHS64-Headsets-With-Built-in-Microphone-3-5mm-In-Ear-Wired-Earphone-For-Smartphones/32854052487.html?spm=2114.search0103.3.1.51dd26c3CxZ3zZ&ws_ab_test=searchweb0_0,searchweb201602_8_10065_10068_319_10059_10884_317_10887_10696_321_322_10084_453_10083_454_10103_10618_10307_537_536,searchweb201603_50,ppcSwitch_0&algo_expid=5587ff37-5e3a-45a8-8206-7b182433a961-0&algo_pvid=5587ff37-5e3a-45a8-8206-7b182433a961'


async function testPupp() {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto(URL);
    await page.evaluate(() => {
        document.querySelector('li[data-trigger="feedback').click();

        console.log(document.body.innerHTML)
    });

    await browser.close();
}


testPupp()

What should I do?

sinusGob
  • 4,053
  • 12
  • 46
  • 82
  • You are looking for an element `#transction-feedback`, which has a misspelling of "transaction". Are you sure it is not `#transaction-feedback`? – sdgluck Apr 22 '19 at 08:24
  • @sdgluck if you go to that link and if you click feedback tap the id is spelled that way. – sinusGob Apr 22 '19 at 08:34

1 Answers1

2

The iframe is the issue: try this code

const puppeteer = require("puppeteer");
const URL =
 "https://www.aliexpress.com/item/Samsung-Earphones-EHS64-Headsets-With-Built-in-Microphone-3-5mm-In-Ear-Wired-Earphone-For-Smartphones/32854052487.html?spm=2114.search0103.3.1.51dd26c3CxZ3zZ&ws_ab_test=searchweb0_0,searchweb201602_8_10065_10068_319_10059_10884_317_10887_10696_321_322_10084_453_10083_454_10103_10618_10307_537_536,searchweb201603_50,ppcSwitch_0&algo_expid=5587ff37-5e3a-45a8-8206-7b182433a961-0&algo_pvid=5587ff37-5e3a-45a8-8206-7b182433a961";

async function testPupp() {
 const browser = await puppeteer.launch({ headless: false });
 const page = await browser.newPage();
 await page.goto(URL, { waitUntil: "networkidle2" });

 // evade popup
 await page.click("body");
 await page.keyboard.press("Escape");

 await page.click('li[data-trigger="feedback');

 // wait for iframe to load
 await page.waitFor(2000);

 const frame = (await page.frames()).find(f => f.url().includes("feedback"));

 await frame.waitFor("#transction-feedback");

 await frame.waitFor(".feedback-item");
 const els = await frame.$$(".feedback-item");
 for (const el of els) {
  const text = await (await el.getProperty("textContent")).jsonValue();
  console.log(text.trim().replace(/\s\s+/g, " "));
 }

 await browser.close();
}

testPupp();
Matthew Scragg
  • 4,540
  • 3
  • 19
  • 27