Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda