首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何打印到Json文件。指纹到终点站,打开Json。无数据传输

如何打印到Json文件。指纹到终点站,打开Json。无数据传输
EN

Stack Overflow用户
提问于 2022-06-26 18:51:52
回答 1查看 40关注 0票数 -1

如何解决如何将此输出打印到结构化json?

此代码创建json文件,并在我的终端中打印响应。但不将结构化数据发送到json文件。

代码语言:javascript
复制
from seoanalyzer import analyze
from bs4 import BeautifulSoup
site = 'http://www.microblink.com'

output = analyze(site, follow_links=False)

with open("output.json", "w", encoding = 'utf-8') as file:

    print(output)

//样本产出:

代码语言:javascript
复制
{'pages': [{'url': 'http://www.microblink.com', 'title': 'microblink: ai-driven technology for solving real life problems', 'description': 'create amazing experiences, verify users at scale and automate your document-based workflow with ai tech built for a remote world.', 'word_count': 659, 'keywords': [(17, 'identity'), (13, 'verification'), (9, 'microblink'), (8, 'technology'), (8, 'industries'), (7, 'contact'), (6, 'document'), (6, 'blog'), (5, 'resources'), (5, 'experiences'), (5, 'customers')], 'bigrams': Counter({'identity verification': 10, 'sign up': 3, 'your customers': 3, 'verification in': 3, 'able to': 3, 'we re': 3, 'identity identity': 2, 'verification document': 2, 'document verification': 2, 'verification identity': 2, 'identity document': 2, 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-26 18:55:48

您刚刚用with open("output.json", "w", encoding = "utf-8") as file打开了json文件,没有向它写任何东西。

要将数据保存到json文件中,需要将数据转储到json文件中。

代码语言:javascript
复制
with open("output.json", "w", encoding = 'utf-8') as file:

    print(output)
    json.dump(output, file)

为此,您需要在代码中使用import json

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72764341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档