V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
moxiaowei
V2EX  ›  问与答

字符串转化问题

  •  
  •   moxiaowei · 2018-10-18 16:48:32 +08:00 · 991 次点击
    这是一个创建于 2232 天前的主题,其中的信息可能已经有所发展或是发生改变。

    比较喜欢玩梦幻西游,最近准备买号,自己看梦幻藏宝阁呢 又没空,就想着用 scrapy 抓点符合要求的数据回来,但是,当抓到用户关键信息的时候,网易返回给我的是类似下面的一段字符串,我想着给他转成一个字典或者 python 内部能识别的数据格式,但是我发现我真的不知道怎么转化。我目前的方案之后一个,那就是正则匹配,但是我感觉正则匹配是不是蠢了点。有没有大神帮我解决下这个问题的。

    这儿是返回的字符串:(我已经做好了换行,记住是一个字符串,不是 python 的 list、tuple、dict)

    	'([
                "farm_level":"3",
                "usernum":10836654,
                "iMaxExpt3":20,
                "iBeastSki4":17,
                "rent":88332,
                "iCGTotalAmount":30,
                "xianyu":12,
                "iHp_Max":2711,
                "more_attr":(["attrs":({(["lv":0,"idx":1,]),(["lv":0,"idx":3,]),(["lv":0,"idx":9,]),(["lv":0,"idx":12,]),(["lv":0,"idx":8,]),(["lv":0,"idx":6,]),(["lv":0,"idx":11,]),(["lv":0,"idx":7,]),(["lv":0,"idx":5,]),(["lv":0,"idx":4,]),(["lv":0,"idx":2,]),(["lv":0,"idx":10,]),(["lv":129,"idx":13,]),(["lv":444,"idx":14,]),}),]),
    
                    "AllRider":([7:(["mattrib":"","ExtraGrow":0,"exgrow":12904,"iGrade":125,"iType":508,"all_skills":([]),]),5:(["mattrib":"","ExtraGrow":0,"exgrow":13106,"iGrade":125,"iType":503,"all_skills":([]),]),4:(["mattrib":"体质","ExtraGrow":0,"exgrow":13112,"iGrade":125,"iType":502,"all_skills":([611:1,]),]),6:(["mattrib":"魔力","ExtraGrow":100,"exgrow":23075,"iGrade":125,"iType":508,"all_skills":([600:2,601:3,]),]),2:(["mattrib":"力量","ExtraGrow":90,"exgrow":22297,"iGrade":125,"iType":503,"all_skills":([600:2,601:3,]),]),]),
    
                "iLearnCash":8213515,
                "iBadness":0,
                "ExAvt":([11:(["order":7,"cName":"锦绣幻梦","iType":12823,]),9:(["order":11,"cName":"藤蔓蔓延","iType":14694,]),6:(["order":4,"cName":"落星织","iType":12750,]),2:(["order":5,"cName":"蓝色妖姬","iType":14404,]),1:(["order":10,"cName":"星光熠熠","iType":21513,]),3:(["order":9,"cName":"锦绣幻梦","iType":12817,]),10:(["order":8,"cName":"两心相悦","iType":14654,]),8:(["order":6,"cName":"星光熠熠","iType":21514,]),7:(["order":1,"cName":"萌草发卡","iType":13696,]),39:(["order":2,"cName":"狼牙棒","iType":11169,]),40:(["order":12,"cName":"怀旧巨魔王炫卡","iType":19287,]),4:(["order":3,"cName":"落星织","iType":40013,]),]),
    
                "iDef_All":410,
                "iSewski":472,
                "iSumAmount":9,
                "iSpe_All":119,
                "iMaxExpt4":20,
                "sword_score":1000,
                "AchPointTotal":4520,
                "iGoodness":7230,
                "addPoint":28,
                "iSumAmountEx":1,
                "cName":"水儋澹兮生烟",
                "iSaving":0,
                "rent_level":5,
                "iBeastSki3":17,
    
                ......
        )]'
    
    kslr
        1
    kslr  
       2018-10-18 17:17:04 +08:00
    网页返回的是 JSON
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1018 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 20:49 · PVG 04:49 · LAX 12:49 · JFK 15:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.