https://discord.gg/botpress logo
#💻developers
Title
# 💻developers
c

chilly-jelly-89366

03/06/2024, 9:21 AM
What is wrong on this script for code execution card?
Copy code
// parse HTML code
await axios
  .get(`https://pubmed.ncbi.nlm.nih.gov/?term=${encodeURIComponent(workflow.rawQuery)}`)
  .then((response) => {
    const html = response.data

    const regex = /<div.*?data-permalink-url="(.*?)".*?>/g
    let matches
    const permalinks = []

    while ((matches = regex.exec(html)) !== null && permalinks.length < 20) {
      permalinks.push(matches[1])
    }

    workflow.pubmedSr_array = permalinks
  })
  .catch((error) => {
    console.error('An error occurred while getting or processing the HTML:', error)
  })
i already have the necessary workflow variables and I have a text card after code execution that prints the array
workflow.pubmedSr_array
My goal is to retrieve the full HTML code from "https://pubmed.ncbi.nlm.nih.gov/?term=" where is my workflow variable 'rawQuery'. After retrieving the HTML source, the script must parse, from the first 20 divs that meet the condition of having the attribute "data-permalink-url", the value of that attribute (in example: data-permalink-url='https://pubmed.ncbi.nlm.nih.gov/23226953/'). Each time the script takes one value from one div, it must store that inside a my array, a workflow variable called: pubmedSr_array