Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fetch data from website which is loaded after few seconds using jquery and ajax

I am trying to fetch data from the website using jquery and $.get. But the problem is that I am not getting all website HTML. Actually, website is loaded in a few seconds and my code is returning part of HTML. The website may be using lazyload feature and $.get does not wait for whole website to load. How do I fetch the data using jquery ajax until the whole website loads?

There is no stuff found on google how to fix it. Please, I need help with this.

$(function () {
  let url =
    'https://shopee.co.th/ผ้าคลุมรถ​-size-s-hi-pvc-i.54771120.2666032196'

  $.get(url, function (data, status) {
    let elements = $(data)
    let stock = elements
      .find('._3DepLY font')
      .last()
      .text()

    console.log(stock)
  })
})

I expect output to be "There are 10 products." but the actual output is empty

like image 364
Junaid Rehman Avatar asked Jan 28 '26 17:01

Junaid Rehman


1 Answers

Requesting in that way will not works as you expect, as you said, there is a lazy loading and part of content are loaded only after some kind of client/browser interaction.

Try to find out in which url this information is made available. Try looking in the Network tab of your browser (developer tools). Once you know, use this address to get product information. Be sure to check out the CORS headers.

like image 111
Marcelo Vismari Avatar answered Jan 30 '26 06:01

Marcelo Vismari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!