The easiest option is to parse the contents in this situation to me through the use of regular expressions , since essentially it is one big line. And due to the fact that you know the key of the desired parameter in advance, it can be done quite simply with the following regular expression:
/"market_hash_name":"(.*?)"/
The required substring must begin with "market_hash_name":"
and end "
, while we want to separately capture what is inside the quotation marks, what can be done with (.*?)
Where .
- any character, *
- repeated any number of times ?
- the search will be executed before the first "
double quote, ie in the" non-greedy mode "(otherwise it will work until the very last quote in the entire line).
// предположим, что переменная scriptTag - DOM элемент того самого скрипта // получаем его содержимое в качестве строки var content = scriptTag.innerHTML; var pattern = /"market_hash_name":"(.*?)"/; var match = content.match(pattern); // под индексом 0 будет храниться результат всего выражения // под индексом 1 - результат захватывающей группы (.*?) var name = match[1]; console.log(name); // "P90 | Fallout Warning (Field-Tested)"
A live example is here: http://jsbin.com/faposoteci/edit?html,js,console
script
tag? - Petr Abdulin