I am trying to build an API for my homework. API is supposed to get info from HTML tag <a>. I need its href and text. It works for some parts of the website, for some it doesn't.
I gave the correct url, so that is not the problem. Also I can't get an error from terminal, or browser.
I inspected 2 element from 2 sites , first one works second doesn't.
This is the one I can read and get
<a href="/oto-bahce-yapi/goodyear-175-65-r14-82h-eagle-sport-2-yaz-lastigi-uretim-tarihi-7-hafta-2022/" class="name-price" title="Goodyear 175/65 R14 82H Eagle Sport 2 Yaz Lastiği (Üretim Tarihi: 7.Hafta 2022)" tabindex="0">
and this is the one I cant read
<a href="/market/indo-mie-noodle-paket-jumbo-sebzeli-120-g/" class="name-price" title="Indo Mie Noodle Paket Jumbo Sebzeli 120 g" rel="bookmark">
In return of second one i get an empty array, first one works fine
Part of my code
const urunler = [];
marketler.forEach((market) => {
axios.get(market.adress).then((response) => {
const html = response.data;
const $ = cheerio.load(html);
$('a[class="name-price"]', html).each(function () {
const urunadi = $(this).text();
const url = $(this).attr("href");
urunler.push({
urunadi,
url: market.base + url, //if need a base
kaynak: market.name,
});
});
});
});
What do you think is the problem or solution?