使用python从Javascript响应中提取JSON数据

时间:2021-09-19 18:24:39

In scraping a website, I am getting given javascript code as a response from the server.

在抓取网站时,我将获得javascript代码作为服务器的响应。

document.write("<script src='/src/one/data.cached.js?ver=9153'></script>");
amorphic.setApplication('one');
amorphic.setSchema(
  {
    "Address": {"customer": 1},
    "Person": {"customer": 1},
    "Phone": {"customer": 1}
  }
);

So, how can I extract this json data from the response using python?

那么,如何使用python从响应中提取这个json数据呢?

  {
    "Address": {"customer": 1},
    "Person": {"customer": 1},
    "Phone": {"customer": 1}
  }

1 个解决方案

#1


0  

Finally extracted the required data from the response using Regular expression operations - re package.

最后使用正则表达式操作 - 重新包来从响应中提取所需的数据。

Seems like this is the only way to extract json data from javascript response.

似乎这是从javascript响应中提取json数据的唯一方法。

Heartily thanks to Prashant Puri and Barmar for their quick and great help.

衷心感谢Prashant Puri和Barmar的快速而有力的帮助。

#1


0  

Finally extracted the required data from the response using Regular expression operations - re package.

最后使用正则表达式操作 - 重新包来从响应中提取所需的数据。

Seems like this is the only way to extract json data from javascript response.

似乎这是从javascript响应中提取json数据的唯一方法。

Heartily thanks to Prashant Puri and Barmar for their quick and great help.

衷心感谢Prashant Puri和Barmar的快速而有力的帮助。