V
V
Vlad Demchuk2021-01-11 14:55:40
JavaScript
Vlad Demchuk, 2021-01-11 14:55:40

How to parse SRC of JS images (axios, cherio)?

I am writing a scraper, it should collect information about the car, the situation is such that I took all the text part I needed, but I don’t know how to get the link to the image of the car itself, I’m waiting for your help guys.

Here's what the code looks like on the site from which I take the information:
5ffc3a5586c58158107636.png

But I already have such information:
5ffc3b7299017286357228.png

Ideally, I'll give you a link to the picture and you're done.

Here is part of the code:

const axios = require('axios');
const cheerio = require('cheerio');
const { strict } = require('assert');
const express = require('express');

const mongoose = require('mongoose');
const url = 'https://auto.ria.com/uk/car/volkswagen/?page=4';

axios.get(url)
    .then(response => {
        //console.log(response.data);
        getData(response.data)
    })
    .catch( error => {
        console.log(error);
    })

    let getData = html => {
        data = [];
        const $ = cheerio.load(html);
        $('.content-bar').each((i, elem) => {
            data.push({
                title : $(elem).find('.head-ticket').text(),
                money : $(elem).find('.size22').text(),
                characteristic: $(elem).find('.characteristic').text(),
                descriptions : $(elem).find('.descriptions-ticket').text(),
                link : $(elem).find('a.m-link-ticket').attr('href')
            });          
        });
    }


Thanks in advance to everyone who helps.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vlad Demchuk, 2021-01-12
@VladDemchuk

The solution is below.

B
bqio, 2021-01-11
@bqio

const regexp = /src="(.*?)"/gm
const html = await axios.get(URL);
let result;
let arr = [];
while ((result = regexp.exec(html.data)) !== null) {
  arr.push(result[1]);
}

Adjust the regulator for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question