OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Function javascript for google sheets scraping web error

  • Thread starter Thread starter alejandro101
  • Start date Start date
A

alejandro101

Guest
Tried to perform a javascript function for Google Sheets for webscaping in order to extract data from the site, in particular the share price of a company.

I have the following error: Exception: Error on line 17: Attribute name "async" associated with an element type "script" must be followed by the ' = ' character. obtenerValorBarrickGold

Code:
function obtenerValorBarrickGold() {
  var url = "https://es.investing.com/equities/barrick-gold-corp.";
  var options = {
    "muteHttpExceptions": true
  };
  
  // Fetch the HTML content of the URL
  var response = UrlFetchApp.fetch(url, options);
  var html = response.getContentText();
  
  // Parse the HTML content
  var doc = XmlService.parse(html);  
  var root = doc.getRootElement();

  // Extract the desired value using XPath
  var xpath = XmlService.getXPath();
  var elements = xpath.selectNodes(doc, "/html/body/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]/div[3]/div[1]/div[1]/div[1]");

  
  if (elements.length > 0) {
    var valor = elements[0].getText();
    return valor;
  } else {
    return "No se pudo encontrar el valor.";
  }
}

<p>Tried to perform a javascript function for Google Sheets for webscaping in order to extract data from the site, in particular the share price of a company.</p>
<p>I have the following error:
Exception: Error on line 17: Attribute name "async" associated with an element type "script" must be followed by the ' = ' character.
obtenerValorBarrickGold</p>
<pre><code>
function obtenerValorBarrickGold() {
var url = "https://es.investing.com/equities/barrick-gold-corp.";
var options = {
"muteHttpExceptions": true
};

// Fetch the HTML content of the URL
var response = UrlFetchApp.fetch(url, options);
var html = response.getContentText();

// Parse the HTML content
var doc = XmlService.parse(html);
var root = doc.getRootElement();

// Extract the desired value using XPath
var xpath = XmlService.getXPath();
var elements = xpath.selectNodes(doc, "/html/body/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]/div[3]/div[1]/div[1]/div[1]");


if (elements.length > 0) {
var valor = elements[0].getText();
return valor;
} else {
return "No se pudo encontrar el valor.";
}
}


</code></pre>
 

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top