推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
sola97
V2EX  ›  Python

如何把一个字典插到数据库里?

  •  
  •   sola97 · Sep 15, 2016 · 3289 views
    This topic created in 3664 days ago, the information mentioned may be changed or developed.

    爬虫爬到的字典数据,只会分成两个列表然后构造 sql 语句 有没有简洁的写法?

    11 replies  •  2016-09-27 15:30:37 +08:00
    virusdefender
        1
    virusdefender  
       Sep 15, 2016 via iPhone
    json
    CosimoZi
        2
    CosimoZi  
       Sep 15, 2016
    尽量不要二次解析
    techmoe
        3
    techmoe  
       Sep 15, 2016 via Android
    我也不想二次解析,但是在不考虑检索条件下 dumps 成 json 的确是一个很好理解也很方便的办法。
    keenkiller
        4
    keenkiller  
       Sep 15, 2016 via Android
    用 mongo
    Arthur2e5
        5
    Arthur2e5  
       Sep 15, 2016
    json 在不少数据库里面都有专门的数据格式支持,所以说真的……(
    reus
        6
    reus  
       Sep 16, 2016
    用 postgres 的 jsonb 类型,支持索引
    qq7171891
        7
    qq7171891  
       Sep 19, 2016
    我直接存,读出来的时候用 eval()还原。
    Arthur2e5
        8
    Arthur2e5  
       Sep 27, 2016
    @qq7171891 暂时不吐槽你在 Python 版里面 eval JSON ,我先告诉你这样子对 JS 都行不通:

    http://timelessrepo.com/json-isnt-a-javascript-subset

    JS 也好, Py 也好,为什么就是不愿意去用专门的东西呢?
    Arthur2e5
        9
    Arthur2e5  
       Sep 27, 2016
    @qq7171891 (啊…继续歪楼。)

    其实刚才直接说不能 eval 也不对,至少 ES5 是可以了, JSON 设计目标之一也是这个: https://github.com/judofyr/timeless/issues/57

    问题是明明可以避免数据库中邪恶管理员插入的任意代码执行的……
    Arthur2e5
        10
    Arthur2e5  
       Sep 27, 2016
    (对不起,我把 issue 看错了……啊自己真是的。)
    qq7171891
        11
    qq7171891  
       Sep 27, 2016
    @Arthur2e5 这。。。。。没事。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2557 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 04:50 · PVG 12:50 · LAX 21:50 · JFK 00:50
    ♥ Do have faith in what you're doing.