I am trying to scrape the website below and I am not getting the value of the attribute 'data-link'.

Could someone help me?

//attempt #1 (error)

const puppeteer = require('puppeteer')

let scrape = async () => {

const browser = await puppeteer.launch({headless: true})

const page = await browser.newPage()

await page.goto('http://www.apptrace.com/itunes/charts/USA/topfreeapplications/36')

await page.waitFor(1000)

const countryCharts = await page.evaluate(() => {

const abbrAppsCountry = []

document.getElementById('#current_storefront_list')

.getAttribute('li > a[data-link]')

.forEach(app => abbrAppsCountry.push(app.value))

return abbrAppsCountry

})

browser.close()

return countryCharts

}

scrape().then((value) => {

console.log(value)

})

//attempt #2 (array of nulls)

const puppeteer = require('puppeteer')

let scrape = async () => {

const browser = await puppeteer.launch({headless: true})

const page = await browser.newPage()

await page.goto('http://www.apptrace.com/itunes/charts/USA/topfreeapplications/36')

await page.waitFor(1000)

const countryCharts = await page.evaluate(() => {

const abbrAppsCountry = []

document.querySelectorAll('#current_storefront_list > li > a[data-link]')

.forEach(app => abbrAppsCountry.push(app.value))

return abbrAppsCountry

})

browser.close()

return countryCharts

}

scrape().then((value) => {

console.log(value)

})

I would like to get the abbreviation of country names.

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐