Last active
March 7, 2018 00:05
-
-
Save 17number/77f21a03d3cf0e28a25fcdc641f537a5 to your computer and use it in GitHub Desktop.
GASで仮想通貨取引所の脆弱性診断
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getObservatoryScores() { | |
var book = SpreadsheetApp.openById('SpreadSheetKey'); | |
var sheetData = book.getSheetByName("シート1"); | |
var pjsApiKey = 'ApiKey'; | |
var urlBasePre = 'https://phantomjscloud.com/api/browser/v2/' + pjsApiKey + '/?request=%7Burl:%22' | |
var urlBasePost = '%22,renderType:%22html%22%7D'; | |
var colURL = 3; | |
var colGrade = 6; | |
var colScore = 7; | |
var colDate = 8; | |
var rowStartData = 2 | |
var rowEndData = sheetData.getDataRange().getLastRow() | |
for(var i = rowStartData; i <= rowEndData; i += 1) { | |
var url = sheetData.getRange(i, colURL).getValue(); | |
var fetchURL = urlBasePre + url + urlBasePost; | |
var response = UrlFetchApp.fetch(fetchURL); | |
var html = response.getContentText('UTF-8'); | |
var grade = getData(html, '<span class="grade-letter" id="scan-grade-letter">', '</span>') + getData(html, 'id="scan-grade-modifier">', '</sup>'); | |
var score = getData(html, '<span id="scan-score">', '</span>'); | |
if(grade === "" || score === "") continue; | |
sheetData.getRange(i, colGrade).setValue(grade); | |
sheetData.getRange(i, colScore).setValue(score); | |
var d = new Date(); | |
sheetData.getRange(i, colDate).setValue(Utilities.formatDate(d, 'Asia/Tokyo', 'yyyy/MM/dd HH:mm:ss')); | |
} | |
sortByScore(sheetData); | |
} | |
function getData(html, startTag, endTag) { | |
var searchTag = startTag; | |
var index = html.indexOf(searchTag) | |
if(index !== -1) { | |
var html = html.substring(index + searchTag.length); | |
var index = html.indexOf(endTag); | |
if(index !== -1) { | |
return html.substring(0, index); | |
} | |
} | |
return ""; | |
} | |
function sortByScore(sheetData){ | |
var sortRange = sheetData.getRange("A2:H"); | |
sortRange.sort([{column: 7, ascending: false}]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment