zoukankan      html  css  js  c++  java
  • 使用 Json 文件存储

    将爬取到的数据以 Json 文件形式存储:

    import json
    import requests
    
    req = requests.get('http://www.baidu.com/')
    
    data = {
        'code': req.status_code,
        'url': req.url,
        'text': req.text
    }
    
    with open('/tmp/1.json', 'w') as fd:
        json.dump(data, fd)

    结果如下:

    {
        "code":200,
        "url":"http://www.baidu.com/",
        "text":"<!DOCTYPE html>......</html>"
    }

        

  • 相关阅读:
    BOM-DOM
    JavaScript
    CSS(2)
    CSS(1)
    HTML5
    索引
    数据库多表查询
    数据操作
    数据库表操作
    初识Java
  • 原文地址:https://www.cnblogs.com/pzk7788/p/10534720.html
Copyright © 2011-2022 走看看