Answer the question
In order to leave comments, you need to log in
How to extract a string from HTML via JavaScript?
I want to parse the price of the swing so I can keep track of when it drops. But I do not know how to make the script work with minimal resources.
Where to spar.
I found that there is a line in the source code (line 84)
So far I have only written this code:"productCost": 16990,
if (OUTPUT_HTML.indexOf('"productCost":') !== -1) {
const PRODUCT_COST_INDEX = OUTPUT_HTML.indexOf('"productCost":');
}
Answer the question
In order to leave comments, you need to log in
indexOf has a second parameter.
function findInString(OUTPUT_HTML, before, after) {
let start = OUTPUT_HTML.indexOf(before);
if (start === -1)
return '';
start += before.length;
const end = OUTPUT_HTML.indexOf(',', start);
if (end === -1)
return '';
return OUTPUT_HTML.slice(start, end);
}
const productCost = +findInString(OUTPUT_HTML, '"productCost":', ',');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question