将爬取到的数据以 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>"
}

 

 

 

 

 

 

 

    

相关文章:

  • 2021-08-16
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
猜你喜欢
  • 2021-10-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2021-08-03
相关资源
相似解决方案