2

I am using cheerio to scraper data off a page and when I try to get the img src it gives me a weird output.

const cheerio = require("cheerio")
require('isomorphic-fetch');

function scrapeAll(){
    nikeScraper()
 }

async function nikeScraper(){
const data = {}
const url = "https://www.nike.com/w/sale-shoes-3yaepzy7ok"
const response = await fetch(url)
const html = await response.text()
const $ = await cheerio.load(html)

const title = $(".product-card__title").each((index, el) => {
    const item = $(el).text()
    data[index] = {}
    data[index].title = item
})
const price = $(".product-price__wrapper").each((index, el) => {
    const item = $(el).text().trim().split("$")
    data[index].sale = item[1]
    data[index].retail = item[2]
})
const link = $(".product-card__img-link-overlay").each((index, el) => {
    const item = $(el).attr("href")
    data[index].link = item
})
const img = $("img").attr("src")

console.log(img)
//console.log("Nike", data)
}
scrapeAll()

This is the console.log(img) output.

data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D

All the other data comes out as it should but this is not giving the src for some reason.

ILally
  • 319
  • 1
  • 8
  • 13
BFP
  • 124
  • 1
  • 9
  • 1
    This looks like the raw image data...try creating an image element and placing this in the src. I don't believe the console can actually render images. However, this seems too short to be an actual image, so there might be something wrong here with your scraping methods. – marsnebulasoup Oct 26 '20 at 20:22
  • 2
    It's a valid image source, it's base64. See [this answer](https://stackoverflow.com/questions/6926016/nodejs-saving-a-base64-encoded-image-to-disk) – Phix Oct 26 '20 at 20:30
  • It doesn't seem to be much of an image though...[see this demo](https://repl.it/@marsnebulasoup/FrostyShimmeringOperation#index.html) – marsnebulasoup Oct 26 '20 at 20:32
  • alright i didnt know what a base64 was till now. but are you able to render it? – BFP Oct 26 '20 at 20:52
  • What is the image supposed to be? The raw data is probably too short for the image to be anything useful – marsnebulasoup Oct 26 '20 at 21:04
  • the src is a link Nike Free RN Flyknit 2018 Women's Running Shoe – BFP Oct 26 '20 at 21:05

0 Answers0