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,
CodePudding user response:
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.
with open("output.json", "w", encoding = 'utf-8') as file:
print(output)
json.dump(output, file)
For that to work you need to import json
in your code.