Initial commit.

This commit is contained in:
yohan 2020-04-30 14:34:52 +02:00
commit d16963fe74
4 changed files with 71 additions and 0 deletions

7
README.md Executable file
View File

@ -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

37
background.js Executable file
View File

@ -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"]
);

26
manifest.json Executable file
View File

@ -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"
}
}
}

1
pen.svg Executable file
View File

@ -0,0 +1 @@
<?xml version="1.0" ?><svg height="24px" version="1.1" viewBox="0 0 24 24" width="24px" xmlns="http://www.w3.org/2000/svg" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns" xmlns:xlink="http://www.w3.org/1999/xlink"><title/><desc/><defs/><g fill="none" fill-rule="evenodd" id="miu" stroke="none" stroke-width="1"><g id="Artboard-1" transform="translate(-899.000000, -227.000000)"><g id="slice" transform="translate(215.000000, 119.000000)"/><path d="M914.000027,248.002414 L914.000464,232.002414 L914.000464,232.002414 L907.001354,232.002414 L907.000079,248.002414 L914.000027,248.002414 Z M913.998311,249.002414 L910.501672,254 L907.00169,249.002414 L913.998311,249.002414 Z M914.000492,231.002414 L914.000574,228.002414 C914.000574,227 912.99816,227 912.99816,227 L908.004086,227 C908.004086,227 907.001672,227 907.001672,228.002414 L907.001433,231.002414 L914.000492,231.002414 L914.000492,231.002414 Z" fill="#000000" id="editor-pencil-pen-edit-write-glyph" transform="translate(910.500326, 240.500000) rotate(45.000000) translate(-910.500326, -240.500000) "/></g></g></svg>

After

Width:  |  Height:  |  Size: 1.1 KiB