Created
July 19, 2026 13:45
-
-
Save mickael9/c0a1ab3b0c68ed5f5052ff5680958799 to your computer and use it in GitHub Desktop.
Télécharger toutes mes factures EDF
This file contains hidden or 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
| // Aller sur l'espace client EDF, page documents (https://particulier.edf.fr/fr/accueil/espace-client/mes-documents.html#/factures) | |
| // Cliquer sur "Factures" | |
| // Ouvrir les outils de développement (F12 ou Ctrl-Maj-I) et coller ce script dans la console | |
| // Valider avec Entrée | |
| (async function () { | |
| const AFTER = "2020-01-01"; // Télécharger uniquement les factures après cette date | |
| const DELAY = 1000; | |
| const zeroPad = (number, digits = 2) => number.toString().padStart(digits, "0"); | |
| const delay = (timeout) => new Promise((resolve) => setTimeout(resolve, timeout)); | |
| let el = angularVersionsEdf.element($("#edocFactures")); | |
| let svc = el.injector().get("edocRWDService"); | |
| let vm = el.controller(); | |
| let count = 0; | |
| for (let bills of vm.bills) { | |
| for (let account of bills.listOfBillsByAccDTO) { | |
| for (let bill of account.listOfbills) { | |
| let query = new URLSearchParams({ | |
| csrfToken: window.crsfTokenInput, | |
| dn: "FACTURE", | |
| pn: bill.parNumber, | |
| di: bill.documentNumber, | |
| bn: bills.bpDto.bpNumberCrypt, | |
| an: account.accDTO.numAccCrypt, | |
| }); | |
| let date = new Date(bill.creationDate); | |
| let avecBilan = !["PAR011", "PAR611", "PAR911", "PAR009", "PAR010",].includes(bill.parNumber); | |
| let suffix = avecBilan ? " avec bilan" : ""; | |
| let dateString = `${date.getFullYear()}-${zeroPad(date.getMonth() + 1)}-${zeroPad(date.getDate())}`; | |
| if (AFTER && dateString <= AFTER) continue; | |
| let filename = `Facture ${dateString} de ${bill.billAmount}€${suffix}.pdf`; | |
| let url = `https://particulier.edf.fr/services/rest/document/getDocumentGetXByData?${query}`; | |
| console.log(`Téléchargement: ${filename}`); | |
| let response = await fetch(url); | |
| if (response.status != 200) { | |
| throw new Error(`HTTP response ${response.status}: ${response.statusText}`); | |
| } | |
| if (response.headers.get("content-type") !== "application/pdf") { | |
| throw new Error(`Not a PDF`); | |
| } | |
| let link = document.createElement("a"); | |
| let blob = await response.blob(); | |
| link.href = URL.createObjectURL(blob); | |
| link.download = filename; | |
| link.click(); | |
| count++; | |
| await delay(DELAY); | |
| } | |
| } | |
| } | |
| console.log(`${count} factures téléchargées`); | |
| })().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment