如何打印到JSON文件。打印到终端,打开JSON。无数据传输
您如何解决将此输出打印到结构化的JSON?
此代码创建JSON文件,并在我的终端中打印响应。但不会将结构化数据发送到JSON文件。
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)
// 样本输出:
{'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,
How do you solve for getting this output to print to a structured json?
This code creates the json file, and prints the response in my terminal. But does not send the structured data to the json file.
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)
//
Sample output:
{'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,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您刚刚用
打开了JSON文件,并带有打开(“ output.json”,“ w”,encoding =“ utf-8”)作为文件
而无需写任何内容。要将数据保存到JSON文件中,您需要将数据转储到JSON文件中。
为此,您需要在代码中
导入JSON
。You have just opened the json file with
with open("output.json", "w", encoding = "utf-8") as file
without writing anything to it.To save your data to the json file you need to dump the data into the json file.
For that to work you need to
import json
in your code.