How do I save and export an object in the browser console?

2

On the Cashier website, lottery results are displayed in the console in the form of objects.

link

I can give a right-click on the Object line, which contains all the contest data, and then click on "Store as global variables".

A variable with the name "temp1" is created.

Then, I can export such data by giving another right-click on temp1 and clicking "Save as ...".

Then, an external file is generated that I can import later.

Well, what I would like is to automate this process through command lines.

Whether through this medium, store and save, or through some other that you think is simpler and more effective.

Anyway, can you give me some help?

Thank you !!!

    
asked by anonymous 28.07.2018 / 22:02

2 answers

3

Responding to the question of " Using only mouse commands to save a variable or console object to a file ", you can import (or paste) the code below into the console itself and you can use the command console.save() , passing as first parameter to the variable / object and the path of the target file in the second parameter.

(function(console){

console.save = function(data, filename){

    if(!data) {
        console.error('Console.save: No data')
        return;
    }

    if(!filename) filename = 'console.json'

    if(typeof data === "object"){
        data = JSON.stringify(data, undefined, 4)
    }

    var blob = new Blob([data], {type: 'text/json'}),
        e    = document.createEvent('MouseEvents'),
        a    = document.createElement('a')

    a.download = filename
    a.href = window.URL.createObjectURL(blob)
    a.dataset.downloadurl =  ['text/json', a.download, a.href].join(':')
    e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
    a.dispatchEvent(e)
 }
})(console)

Example usage (in the firefox / chrome console):

var a1 = "aaaaaaaaaaaaa";
console.save(a1, "/home/myUser/saida.txt");
    
02.08.2018 / 20:53
2

There is an API that returns you the results of some lotteries in JSON with this you can integrate in almost any application (there goes your need). >

This is her link along with the document:

link

Input example:

link

Return

{
"concurso": {
    "numero": "2062",
    "data": "25/07/2018",
    "cidade": "POUSO REDONDO, SC",
    "local": "Caminhão da Sorte",
    "valor_acumulado": "0,00",
    "dezenas": [
        "08",
        "10",
        "15",
        "23",
        "25",
        "34"
    ],
"premiacao": {
    "sena": {
        "ganhadores": "1",
        "valor_pago": "73.450.153,75"
        },
    "quina": {
        "ganhadores": "192",
        "valor_pago": "27.128,74"
        },
    "quadra": {
        "ganhadores": "13804",
        "valor_pago": "539,04"
        }
    },
        "arrecadacao_total": "90.343.582,00"
        },
    "proximo_concurso": {
        "data": "28/07/2018",
        "valor_estimado": "3.000.000,00"
    },
    "valor_acumulado_final_cinco": "15.139.880,89",
    "valor_acumulado_final_zero": "0,00",
    "mega_virada_valor_acumulado": "40.957.415,53",
    "resultado_completo": "1"
    }
    
28.07.2018 / 22:21