Correction d'un script après modification d'une structuration web

Bonjour,

jusqu'à présent j'utilisais un script pour importer certains éléments d'un site.

la structure du site à changer et maintenant j'ai un

"Truncated server response: {"message":"Forbidden"} (use muteHttpExceptions option to examine full response)"

j'ai bien vu que certains éléments avaient changés mais je n'arrive pas à rectifier le tir !

Voici le script

function Secondary_Market() {

  var url = "https://api.realt-dashboard.co/get-swapcat-offers?chainId=100";
  var classeur = SpreadsheetApp.getActiveSpreadsheet();
  var feuille = classeur.getSheetByName('Market');
  var cell = feuille.getRange('A26:J');

  var response = UrlFetchApp.fetch(url, {
    "method": "GET",
    "headers": {
      "x-api-key": "Syj4wSrL71aasuHntobv19ECxQvJxEDZ7IufOO5u",
      "Content-Type": "application/json"
    }
  });

  cell.clearContent();

  var output = [];
  var json = response.getContentText();
  var realtData = JSON.parse(json);
  for (let i in realtData) {

    if ((1*realtData[i].sellingQuantity/1000000000000000000)>0.1){

    var blockchain = realtData[i].blockchain
    var selling = realtData[i].selling
    var seller = realtData[i].seller
    var buying = realtData[i].buying
    var sellingQuantity = realtData[i].sellingQuantity /1000000000000000000
    var totalPrice =realtData[i].totalPrice
    var house = realtData[i].sellingData.property.name
    var UnitePrice = totalPrice/sellingQuantity
    var UniteCrypto = realtData[i].buyingData.name
    var realPrice = realtData[i].sellingData.token.value
    var offerId = realtData[i].offerId
    var Ecart$ = UnitePrice-realPrice
    var Ecart = Ecart$/UnitePrice

    output.push([selling, blockchain, house, UniteCrypto, UnitePrice, sellingQuantity, '=hyperlink("https://swap.cat/?oid=' + offerId + '&chain=100","achat")', Ecart$]);
  }
    feuille.getRange(26,1, output.length, output[0].length).setValues(output).sort({column: 8, ascending: true});
  } 
}

Voici les éléments du site https://dashboard.realt.community/swapcat

image image

et voici la structure maintenant

image

Merci !

attention, tu as mis ton api-key

ajoute ceci

,followRedirects: true, muteHttpExceptions: true

ici

  var response = UrlFetchApp.fetch(url, {
    "method": "GET",
    "headers": {
      "x-api-key": "###################",
      "Content-Type": "application/json"
    },followRedirects: true, muteHttpExceptions: true
  });

ce n'est pas lié à la structure, maintenant elle a peut-être aussi changé et tu devra adapter le reste, mais au moins tu as une réponse

image

Bonjour

attention, tu as mis ton api-key

C'est celle accessible sur le site.. mais tu as raison j'aurais pû l'enlever ( même si elle est facilement trouvable )

effectivement j'avais mal placé le "mutehhp...." et je n'avais pas du tout connaissance du followRedirects

et merci je vais regarder ça. j'ai l'impression qu'il y a ++ de tableau et sous tableaux je sens que je vais galérer

followRedirects n'était peut-être pas utile ici (mais cela fait partie de mon package !)

Bonjour,

Bon.. je dois mal faire quelque chose car quelque soit la façon de faire j'arrive pas à récupérer les infos

j'ai essayé ton script magique pour tout récupérer ! mais sans succès

function TEST() {
  var url = "https://api.realt-dashboard.co/get-swapcat-offers?chainId=100&v=2";
  var classeur = SpreadsheetApp.getActiveSpreadsheet();
  var feuille = classeur.getSheetByName('TEST');
  var response = UrlFetchApp.fetch(url, {
    "method": "GET",
    "headers": {
      "accept":"<*/*>",
      "X-AUTH-REALT-TOKEN": "Syj4wSrL71aasuHntobv19ECxQvJxEDZ7IufOO5u",
      "Content-Type": "application/json"
    },followRedirects: true, muteHttpExceptions: true
  });

  var output = [];
  var json = response.getContentText();
  var data = JSON.parse(json);
  recursion(data)
  function recursion(obj, path) {
    if (path == undefined) { path = 'data' }
    const regex = new RegExp('[^0-9]+');
    for (let p in obj) {
      let newPath = (regex.test(p)) ? path + '.' + p : path + '[' + p + ']';
      if (obj[p] != null) {
        if (typeof obj[p] != 'object' && typeof obj[p] != 'function') {
          output.push([newPath, p, obj[p]]);
        }
        if (typeof obj[p] == 'object') {
          recursion(obj[p], newPath);
        }
      }
    }
  }
  return output
}
image
[0 … 99]
  0: {chainId: "100", blockchain: "xDai", selling: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF",…}
     blockchain: "xDai"
     chainId: "100"
     offerData: [{offerId: 3434, selling: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF",…},…]
         0: {offerId: 3434, selling: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF",…}
            buying: "0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83"
            buyingData: {name: "USDC on xDai", address: "0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83",…}
               address: "0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83"
               chainId: 100
               decimals: 6
               logoURI: "https://raw.githubusercontent.com/trustwallet/assets/master/blockc...
               name: "USDC on xDai"
               symbol: "USDC"
            buyingPrice: "51500000"
            offerId: 3434
            seller: "0xE15fd22368fAF4BB59980be1A196079D348DFaA8"
            selling: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF"
            sellingQuantity: "360000000000000000000"
            totalPrice: 18540
        1: {offerId: 3435, selling: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF",…}
        2: {offerId: 3711, selling: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF",…}
        3: {offerId: 3472, selling: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF",…}
    selling: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF"
    sellingData: {,…}
        blockchainAddresses: {,…}
            ethereum: {chainName: "Ethereum", chainId: 1, contract: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF",…}
                    chainId: 1
                    chainName: "Ethereum"
                    contract: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF"
                    distributor: "0x5c7fc8af9bcdd0252827fba509d81a33db289db0"
                    maintenance: "0x2944c261Fe6bFbED7e432fcf66a860af7aF7033a"
            xDai: {chainName: "xDaiChain", chainId: 100, contract: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF",…}
                    chainId: 100
                    chainName: "xDaiChain"
                    chainlinkPriceContract: "0xF6766831c87f0930ce406A21DFEc02EFC3B89b91"
                    contract: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF"
                    distributor: "0x5c7fc8af9bcdd0252827fba509d81a33db289db0"
                    rmmPoolAddress: 0
            property: {name: "2911 Sturtevant St, Detroit, MI 48206", shortName: "2911 Sturtevant",…}
                images: ["https://realt.co/wp-content/uploads/2022/06/2911-Sturteant-hero-1.jpg",…]
                    0: "https://realt.co/wp-content/uploads/2022/06/2911-Sturteant-hero-1.jpg"
                    1: "https://realt.co/wp-content/uploads/2022/06/2911-Sturtevant-aerial-2.jpg"
                location: {lat: "42.386413", lng: "-83.121211", city: "Detroit",...}
                    city: "Detroit"
                    country: "United States"
                    lat: "42.386413"
                    lng: "-83.121211"
                    state: "Michigan"
                    name: "2911 Sturtevant St, Detroit, MI 48206"
                    shortName: "2911 Sturtevant"
                    url: "https://realt.co/product/2911-sturtevant-st-detroit-mi-48206/"
                return: {apr: "10.26", perYear: 5.195320754717, perMonth: 0.43294339622642,...}
                    apr: "10.26"
                    perDay: 0.014233755492375
                    perMonth: 0.43294339622642
                    perYear: 5.195320754717
                token: {id: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF",…}
                    from: "0x5c7fc8af9bcdd0252827fba509d81a33db289db0"
                    id: "0x7A684f6d9a34175d642EEdB31FA545604d8d3aCF"
                    name: "REALTOKEN-S-2911-STURTEVANT-ST-DETROIT-MI"
                    supply: 26500
                    uniswap: ""
                    value: 50.62

Voici le détail de la structure

je veux pas forcement tout récupérer mais c'est pour comprendre pourquoi j'y arrive pas surtout

ben mince ! dans mon cas https://forum.excel-pratique.com/sheets/correction-d-un-script-apres-modification-d-une-structuratio... j'avais bien un résultat !

je vais jeter un

avec ceci

function alexElucubrations() {
  var url = "https://api.realt-dashboard.co/get-swapcat-offers?chainId=100&v=2";
  var classeur = SpreadsheetApp.getActiveSpreadsheet();
  var feuille = classeur.getSheetByName('TEST');
  var response = UrlFetchApp.fetch(url, {
    "method": "GET",
    "headers": {
      "accept":"<*/*>",
      "X-AUTH-REALT-TOKEN": "Syj4wSrL71aasuHntobv19ECxQvJxEDZ7IufOO5u",
      "Content-Type": "application/json"
    },followRedirects: true, muteHttpExceptions: true
  });

  var output = [];
  var json = response.getContentText();
  console.log(json)
}

j'ai juste ce résultat !

{"message":"Forbidden"}

j'ai juste ce résultat !

Bah oui je sais C'est tout le problème de mon incompréhension

ps : j'adore le titre de ta fonction

pourtant si je vais sur le site https://dashboard.realt.community/swapcat et que j'inspecte la page..

image

non, cette page ne peut pas être scrapée, ni pat fonctions natives ni par script. Tu peux voir aussi qu'elle se charge au fur et a mesure du scroll. C'est de l'ajax. Il faudrait trouver une autre url ou une api.

ceci ne fait pas ou plus l'affaire ? https://api.realt.community/

ah d'accord. mince ! pourtant je pouvait le faire il y a quelques temps ( avant la version 2 qui est en place actuellement )

non en faite la source exact des annonces viennent de ce site https://ipfs.io/ipfs/QmXfN5VMUU1Q1TvXjvdQtQds9JtMk7gTJeEdWhv8FG6mCq/start.htm

mais la personne qui a Dev ce que je voulais récupérer à fait un travail de fou pour filtrer que les "bonnes annonces" et c'est clairement pas de mon ressort.

Merci en tout cas :)

Rechercher des sujets similaires à "correction script modification structuration web"