简体   繁体   中英

how to fetch a html page(elements) with Js

I am trying to fetch a content of a page. When I inspect and go under the 'Elements' section, I can see the needed data in span tag for example, but when I try to fetch which I do as a get request to the url, I receive different HTML that doesn't contain the same data but less.

This is how I try to fetch my data

async function fetchData(url)
{
  const response = await axios.get(url);
  console.log(response.data)
}

What would be the reason of the difference and how could I solve it?

Should I use different technique?

Well, indeed, crawlers are supposed to use parsing tools, like Puppeteer library or Cheerio for data-grabbing.

Here are some references:

github puppeteer

npm puppeteer

I've tried to do something like that a few times ago. If you're having troubles - ask for help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM