D
D
Damir Karimov2017-09-16 21:10:12
Parsing
Damir Karimov, 2017-09-16 21:10:12

Parsing with Google SpreadSheets. Where is the mistake?

What do you need to pass to start and end to parse the dollar rate from this page( cbr.ru/currency_base/daily.aspx?date_req=08/06/2017)?
HTML code of the page (so you don't have to climb):

<tr><td>840</td>
<td>USD</td>
<td>1</td>
<td>Доллар США</td>
<td>60,3281</td></tr>

My script code:
function getConten(){
  getPageContent("http://cbr.ru/currency_base/daily.aspx?date_req=06.08.2017");
}

function getPageContent(url) {
  var sheet = SpreadsheetApp.getActiveSheet();
  var range = sheet.getRange("A1:B1");
  var cell = range.getCell(1,1);
  
  var response = UrlFetchApp.fetch(url);
  
  var textResp = response.getContentText();
  
  var start, end, name;
  
  var i;
  
  for(i = 0; i < 10; i++){
    start = textResp.indexOf('США</td><td>', end);
    
    end = textResp.indexOf('</td>', start);
    name = textResp.substring(start, end);
    cell.setValue(name);
    cell = cell.offset(1, 0);
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VVB, 2017-09-17
@SEOBot

I haven't looked at the code much, but it seems that the error is "USA"
In the original HTML code, you provided code with a line break between < /td > and < td >

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question