From d16963fe74b588ecff10b6dfdd4c01e5c4838b29 Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Thu, 30 Apr 2020 14:34:52 +0200 Subject: [PATCH] Initial commit. --- README.md | 7 +++++++ background.js | 37 +++++++++++++++++++++++++++++++++++++ manifest.json | 26 ++++++++++++++++++++++++++ pen.svg | 1 + 4 files changed, 71 insertions(+) create mode 100755 README.md create mode 100755 background.js create mode 100755 manifest.json create mode 100755 pen.svg diff --git a/README.md b/README.md new file mode 100755 index 0000000..88de944 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +Abandonné, car pas possible de désactiver CORS dans Firefox contrairement à Chrome. + + root@y1:/home/yohan/boursorama-scraping# apt-get -y install chromium + yohan@y1:~/boursorama-scraping$ chromium --args --user-data-dir="/tmp/chrome_dev_test" --disable-web-security + +## Références : +https://developer.mozilla.org/fr/docs/Mozilla/Add-ons/WebExtensions/Your_first_WebExtension diff --git a/background.js b/background.js new file mode 100755 index 0000000..4c8355a --- /dev/null +++ b/background.js @@ -0,0 +1,37 @@ +function listener(details) { + let filter = browser.webRequest.filterResponseData(details.requestId); + let decoder = new TextDecoder("utf-8"); + let encoder = new TextEncoder(); + + filter.ondata = event => { + let str = decoder.decode(event.data, {stream: true}); + // Just change any instance of Example in the HTTP response + // to WebExtension Example. + //str = str.replace(/Example/g, 'WebExtension Example'); + console.log(str) + console.log(details.url) + + var request = new XMLHttpRequest(); + request.open("POST", "http://ovh1:3000/add"); + request.setRequestHeader("Content-Type", "application/json"); + request.setRequestHeader("X-API-KEY", "FIXME"); + request.overrideMimeType("text/plain"); + request.onload = function() + { + alert("Response received: " + request.responseText); + }; + request.send('{"volume": 1234, "price": 12.3, "metric": "BNP", "time": "2020-04-23T13:31:21.643Z"}'); + + filter.write(encoder.encode(str)); + filter.disconnect(); + } + + return {}; +} + +browser.webRequest.onBeforeRequest.addListener( + listener, + {urls: ["https://www.boursorama.com/bourse/action/graph/ws/UpdateCharts*"], types: ["xmlhttprequest"]}, + ["blocking", "requestBody"] +); + diff --git a/manifest.json b/manifest.json new file mode 100755 index 0000000..79ed6df --- /dev/null +++ b/manifest.json @@ -0,0 +1,26 @@ +{ + + "description": "Scraping Boursorama", + "manifest_version": 2, + "name": "boursorama-scraping", + "version": "1.0", + "homepage_url": "https://github.com/mdn/webextensions-examples/tree/master/http-response", + "icons": { + "48": "pen.svg" + }, + + "permissions": [ + "webRequest", "webRequestBlocking", "https://www.boursorama.com/*" + ], + + "background": { + "scripts": ["background.js"] + }, + + "browser_specific_settings": { + "gecko": { + "strict_min_version": "57.0a1" + } + } + +} diff --git a/pen.svg b/pen.svg new file mode 100755 index 0000000..65a3f42 --- /dev/null +++ b/pen.svg @@ -0,0 +1 @@ +