Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error: Attribute selector didn't terminate

goodnight. I’m trying to scrape data on the transfermarket website, but it’s giving me the error I posted.

I’m using Javascript, Cheerio and Axios.

const fetchData = async(url) => {
    const result = await axios.get(url)
    return result.data
}

const main = async () => {
    const content = await fetchData("https://www.transfermarkt.com.br/premier-league/torschuetzenliste/wettbewerb/GB1/saison_id/2022")
    const $ = cheerio.load(content)
    let artilheiros = []

    $('table.items tbody tr').each((i, e) => {
        const AllElements = $(e).find('td')
        const nomeArtilheiro = $(`${AllElements[1]} > table > tbody > tr.hauptlink > a`).text();
        // const clubeArtilheiro
        // const jogos 
        // const gols 
        const data = {nomeArtilheiro}
        artilheiros.push(data)
    })

    console.log(artilheiros)
}

main()

The error it gave:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

throw new Error("Attribute selector didn't terminate");
Error: Attribute selector didn't terminate

>Solution :

This line is the error:

const nomeArtilheiro = $(`${AllElements[1]} > table > tbody > tr.hauptlink > a`).text();

AllElements[1] is not a string, so its probably turning into "[object Object]"

You should write

$(AllElements[1]).find('table > tbody > tr.hauptlink > a').text()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading