How to save and export an object in the browser console?

Asked

Viewed 907 times

0

on the Box website, the results of the lotteries are displayed on the console in the form of objects.

http://loterias.caixa.gov.br/wps/portal/loterias/landing/megasena/

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

A variable named "temp1" is created.

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

Hence, an external file is generated which I can import later.

Well, what I’d like to do is automate this process through command lines.

Whether through this medium, to store and save, or through some other that you believe to be simpler and more effective.

Anyway, you can give me a hand?

Thank you!!!

  • I don’t know if that’s considered legal

2 answers

1

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

This is her link with the ducumentation:

https://confiraloterias.com.br/api/megasena/

Example of input:

http://confiraloterias.com.br/api0/json.php?loteria=megasena&token=r9hFuFEvYXiZUuj&concurso=2062

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"
    }
  • 1

    Reynaldo puts the code instead of the image, images like code can make it difficult for search engines to index the content and disturb anyone who uses the code.

  • 1

    Reynaldo, thank you for the clarification! I know this API and I could use it. But I have to load from other lotteries also for which this site does not offer support. That is, I will need to learn to fetch the data on the same console! Hence the reason for the post...

1

In answer to the question of "Using only commands (no mouse) to save a console variable or object to a file", you can import (or paste) the code below into the console itself and can use the command console.save(), passing as first parameter the variable/object and the path of the destination 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 of usage (in firefox/Chrome console):

var a1 = "aaaaaaaaaaaaa";
console.save(a1, "/home/myUser/saida.txt");
  • Very good! But, what would be the command to automate the "Store as global variables" also!?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.