I am trying to pull data from the zakupki.mos.ru site with a Google spreadsheet macro, but only gives the start of the page code.

function getPageContent(url) { var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("a1:b1"); var cell = range.getCell(1,1); var response = UrlFetchApp.fetch("https://zakupki.mos.ru/#/offerauction/456060/view"); var textResp = response.getContentText(); var start, end, name; for (var i=1;i<=10;i++){ start = textResp.indexOf('Возможная ставка', end) + 17; start = textResp.indexOf('">', start) + 2; end = textResp.indexOf('</strong>', start); name = textResp.substring(start, end); cell.setValue(name); } } 

    2 answers 2

    Probably what you want to be sparred is pushed down by ajax in json format at this link https://zakupki.mos.ru/api/Cssp/OfferAuction/GetEntity?id=456060 , change id and take the necessary data

    • Cool! Thank! And tell me how the id pull up from the cell, for example, E1? - Alexey Nikitin
    • There is no example on hand, smoking is too lazy. Something like that by searching var values ​​= sheet.getDataRange (). GetValues ​​(); for (var i = 1; i <values.length; i ++) { - Nsk

    You cannot do this.

    This is normal, because The UrlFetchApp.fetch() method returns the response from the server, not the browser state after processing this response. In this case, scraping is not possible.

    To find out whether you can get data from the site in this way, you can install a browser extension that disables the execution of scripts (for example, Quick Javascript Switcher for Chrome). What the browser displays when the extension is enabled, the same will be UrlFetchApp.fetch() .