'Save Beautiful Soup Output to JSON

I have a loop that I am not sure how to close so I can save the output locally as json. My print output looks fine but I am just getting the last line of my output on my json save with the following:

from urllib.request import Request, urlopen

req = Request('https://www.website.com', headers={'User-Agent': 'Mozilla/5.0'})
webpage = urlopen(req).read()
html = webpage.decode('utf8')
type(html)

from bs4 import BeautifulSoup
htmlsoup = BeautifulSoup(html, 'html.parser')
type(htmlsoup)

enter code hereanchors = htmlsoup.find_all('a')
type(anchors)

for a in anchors:
 print(a.text)

filename = 'website.json'

import json
with open(filename, 'w', encoding='utf-8') as f:
    json.dump(a.text, f, ensure_ascii=False, indent=4)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source