So, as an assignment from Thenewboston, I'm trying to grab a block of code from his site and write it to a file. The code grabbing part works just fine, but the writing part doesn't work:
import requests
from bs4 import BeautifulSoup
def crawler(url):
source = requests.get(url)
source_text = source.text
soup_obj = BeautifulSoup(source_text, "html.parser")
for code in soup_obj.find('code'):
codes = str(code)
final_code = codes.replace('<br/>', '').replace('Â', '')
print(final_code)
fx = open('crawler_code.txt', 'w')
fx.write(final_code)
fx.close()
crawler('https://thenewboston.com/forum/topic.php?id=1610')