Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Retrieve array from javascript response

I have a PHP file that responds with a similar javascript response to below.

var count = 0;
var actors = [];
var directors = [];
var movies = ["7​/n​/n# L<DxJ", "7x​/nx​/nxlNTv", "(N​/lN​/lNUnNTv", "}x​/Yx​/YxL#llNTv", "}​/Y​/Y<L<J", "O​/u​;uiLY<J", "@​/J​/JNUL<DxJ"];
var hidden = [];
var r_space = null;
var chars = {
    "i": "N",
    "R": "6",
    "u": "T",
    "a": "i",
    "V": "p",
    ">": "a"
};
for (var i in chars) {
    if (i == ' ') r_space = asta[i];
}

The movie names are encoded using a simple algorithm using var chars. I want to iterate through the var movies and get all values in to an array so I can decode them. I tried using below code to split by ";" and then call [3] to get var movies and then split it by "," to get each movie name and store it an array but the issues is some words in var movies also contain ";".

var_array = str(response.content.decode()).split(";")[3][14:-1].split(",")
for va in var_array:
    print(va[1:-1])

Is there a different way I can get all values in var movies to an array and then decode? Thanks.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use a combination of json and re (regex) modules:

json.loads(re.search("var movies = (?P<movies>\[.+\]);", str(response.content.decode())).group("movies"))

This will result in:

['7\u200b/n\u200b/n# L<DxJ',
 '7x\u200b/nx\u200b/nxlNTv',
 '(N\u200b/lN\u200b/lNUnNTv',
 '}x\u200b/Yx\u200b/YxL#llNTv',
 '}\u200b/Y\u200b/Y<L<J',
 'O\u200b/u\u200b;uiLY<J',
 '@\u200b/J\u200b/JNUL<DxJ']

Then you can simply run a for loop over this list.

about 4 years ago · Juan Pablo Isaza Report

0

try to Use the JavaScript function JSON.parse() to convert text into a JavaScript object and then loop on it to get movies value.

let var_array = JSON.parse(movies);

for va in var_array:

console.log(va)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!