python 優雅的解析 jsonp

来源:https://www.cnblogs.com/skyxing7/archive/2019/09/20/11553491.html
-Advertisement-
Play Games

一段 jsonp 格式數據 方法 ...


一段 jsonp 格式數據

mtopjsonpweexcb1({"api":"mtop.taobao.idle.recycle.nextspunav.get","data":{"ext":{},"items":[{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":true,"hotLabel":true,"hotLabelName":"熱門","subNextPage":false,"subRecycleSpuNavDOList":[{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"name":"MacBook Air 13.3","spuId":506,"subNextPage":false},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"name":"蘋果 Macbook Pro 13 i5五代","spuId":507,"subNextPage":false},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"name":"聯想 拯救者R720","spuId":2102,"subNextPage":false},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"name":"Thinkpad E470C","spuId":2571,"subNextPage":false},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"name":"戴爾 G3 15","spuId":1703808,"subNextPage":false},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"name":"華碩 FX80","spuId":1703725,"subNextPage":false},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"name":"神舟 戰神Z7M","spuId":1677,"subNextPage":false},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"name":"炫龍 毀滅者DC","spuId":72423,"subNextPage":false},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"name":"小米 筆記本Pro","spuId":1443679,"subNextPage":false},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"name":"華為 Matebook X Pro","spuId":1443531,"subNextPage":false}],"subTotalCount":10},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":true,"hotLabel":false,"id":30111,"name":"蘋果","subNextPage":true,"subRecycleSpuNavDOList":[{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":63986242,"name":"蘋果 15年 13寸 MacBook Air","spuId":506,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":2891556036,"name":"蘋果18年13寸MacBookAir","spuId":3439453,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":2891556038,"name":"蘋果18年15寸MacBookPro","spuId":3439455,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":2891556037,"name":"蘋果18年13寸MacBookPro","spuId":3439454,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":88764409,"name":"蘋果 15年 11寸 MacBook Air","spuId":515,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1930119344,"name":"蘋果 14年 13寸 MacBook Pro","spuId":508,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1930119343,"name":"蘋果 15年 13寸 MacBook Pro","spuId":507,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1930119346,"name":"蘋果 15年 15寸 MacBook Pro","spuId":510,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1930119347,"name":"蘋果 14年 15寸 MacBook Pro","spuId":511,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1979880045,"name":"蘋果 16年 13寸 MacBook Pro","spuId":1327136,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1979880044,"name":"蘋果 16年 15寸 MacBook Pro","spuId":1327138,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1979880046,"name":"蘋果 17年 13寸 MacBook Pro","spuId":1327137,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1979880043,"name":"蘋果 17年 15寸 MacBook Pro","spuId":1327139,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1979880047,"name":"蘋果 17年 12寸 MacBook","spuId":1327135,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":863236658,"name":"蘋果 16年 12寸 MacBook","spuId":505,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1979880048,"name":"蘋果 塑料殼 09年 13寸 MacBook","spuId":1327134,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1930119349,"name":"MacBook Pro 15 酷睿系列","spuId":513,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1930119348,"name":"MacBook Pro 15 酷睿i系列","spuId":512,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1930119345,"name":"MacBook Pro 13 機械硬碟","spuId":509,"subNextPage":false,"type":"keyProp2Id"},{"bannerFlag":false,"hasNextLevel":false,"hasReturnNextLevel":false,"hotLabel":false,"id":1581598684,"name":"新款Macbook Pro 15英寸","spuId":518,"subNextPage":false,"type":"keyProp2Id"}],"subTotalCount":23,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":11119,"name":"聯想","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":11656,"name":"華碩","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":26683,"name":"戴爾","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":184048021,"name":"ThinkPad","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":21660,"name":"神舟","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":31140,"name":"惠普","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":26691,"name":"巨集碁","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":123574,"name":"alienware","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":81156,"name":"三星","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":21989,"name":"微軟","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":4535518,"name":"雷蛇","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":676006358,"name":"炫龍","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":21999,"name":"微星","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":10752,"name":"索尼","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":775486237,"name":"機械革命","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":10745,"name":"東芝","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":527976624,"name":"麥本本","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":616784001,"name":"機械師","subNextPage":false,"type":"keyProp1Id"},{"bannerFlag":false,"hasNextLevel":true,"hasReturnNextLevel":false,"hotLabel":false,"id":11016,"name":"海爾","subNextPage":false,"type":"keyProp1Id"}],"needDecryptKeys":[],"nextPage":true,"serverTime":"2019-08-06 19:40:09","totalCount":28},"ret":["SUCCESS::調用成功"],"v":"1.0"})

方法

import json, re
def loads_jsonp(self, _jsonp):
        """
        解析jsonp數據格式為json
        :return:
        """
        try:
            return json.loads(re.match(".*?({.*}).*", _jsonp, re.S).group(1))
        except:
            raise ValueError('Invalid Input')

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • lambda演變歷史 .NetFramework1.0 1.1下,lambda表達式是這樣去寫的,首先聲明一個無參無返回值delegate委托,再聲明一個無參無返回值的方法,把這個方法當做參數一樣傳遞給委托 你也可以聲明一個有參數和有返回值的委托,就像聲明方法一樣: .NetFramework2.0 ...
  • 又一個新的名詞(taghelper),通過taghelper是可以操作html標簽、條件輸出、更是自由添加內外元素。當然也內置了挺多的asp 開頭的taghelper。 下麵文章中也簡單的帶大家實現一個taghelper; 創建自定義html元素 創建一個類ButtonTagHelper tagNa ...
  • 準備: ADFS安裝配置 https://www.cnblogs.com/luoyedemeng/articles/9837685.html 添加一個Providers 配置ADFS 設置你的identityServer地址 設置你的urn 我的是:urn:identityServer 接下來一路下 ...
  • 一、問題 新項目是基於 ABP vNext 框架進行開發的,所以我要求為每層編寫單元測試。在同事為某個倉儲編寫單元測試的時候,發現了一個奇怪的問題。他的對某個聚合根的 A 欄位進行了更新,隨後對某個導航屬性 B 也進行了變更,最後通過倉儲提供的 方法對變更的數據進行持久化。 結果再次查出來的時候,發 ...
  • 場景 FastReport安裝包下載、安裝、去除使用限制以及工具箱中添加控制項: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100893794 Winform中使用FastReport實現簡單的自定義PDF導出: https:/ ...
  • 最近在做identityServer3+ADFS 實現域賬號第三方授權驗證,發現一個問題,在我們網站跳轉到域賬戶登錄頁面,這個頁面有點不美觀,那麼我們改如何自定義這個登錄界面呢? ADFS安裝配置這裡不做提示,百度大把資料,identityServer3+ADFS全網沒有資料,整理出來還需要點時間, ...
  • 原文地址:https://www.cnblogs.com/yinrq/p/5381492.html 一、前言 Autofac是.NET領域最為流行的IOC框架之一,微軟的Orchad開源程式使用的就是Autofac,Nopcommerce開源程式也是用的Autofac。 Orchad和Nopcomm ...
  • 1.Docker容器概述 區分Docker容器技術和VM虛擬機技術: evernotecid://394EFE90 9CE0 4D65 A8CD DFEC0DC8061E/appyinxiangcom/11359837/ENResource/p1872 Docker容器技術 [Container]: ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...