Home > Software engineering >  Webscraper only gets half of requested text
Webscraper only gets half of requested text

Time:02-10

When it scrapes data only "odds" is displayed and "odds-name" is 'undefined. I'm not sure what I'm doing wrong.

This is a part of html code from website I'm trying to scrape

    <span >14.50</span>
        <span >manje (0.5)
    <span >
        <span >
            764050
        </span>
    </span>
</span>
    <span >1.03</span>
        <span >više (0.5)
    <span >
        <span >
            764050
        </span>
    </span>
</span>

And here's the code

const axios = require('axios')
const cheerio = require('cheerio')
const express = require('express')

const app = express()

const url = "website link"

axios(url)
    .then(response => {
        const html = response.data
        const $ = cheerio.load(html)
        const odd = []

        $(".odds-value", html).each(function(){
            const odds = $(this).text()
            const odds_name = $(this).find('span').attr('odds-name')
            odd.push({
                odds,
                odds_name
            })
        })
        console.log(odd)
    }).catch(err => console.log(err))

app.listen(PORT,() => console.log('server running on PORT${PORT}'))```




CodePudding user response:

  •  Tags:  
  • Related