Search code examples
javascriptnode.jsweb-scrapingaxiosjavascript-objects

What is role the of url in async function in web scrapping


I am working on web scrapping and I came across one scenario where I am get confused about arrow key function,I am unable to understand why url is used twice and how it is actual working, I know it is advanced javascript but I need some explanation to understand this completely.

first Url in arrow function:

const fethHtml = async url => {

Second url pass in axios.get

await axios.get(url);

const fethHtml = async url => {

const axios = require("axios").default;

const fethHtml = async url => {
  try {
    const { data } = await axios.get(url);
    return data;
  } catch {
    console.error(
      `ERROR: An error occurred while trying to fetch the URL: ${url}`
    );
  }
};

My question is what url is indicating here is it variable or function and why it is called twice, I didn't found any explanation anywhere.


Solution

  • const fethHtml = async url => {

    url is just arguments. (ex:google.com)

    then pass the arguments to axios to get resposne.

    await axios.get(url);