Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda