I am attempting to save the text in a beautiful soup object to a file, that I can later edit and use. I've got all necessary modules imported, but for some reason I get the same error every time at "pagename.write(str(soup))" I've tried rewriting this multiple way and I am just stumped
#Testing implementation of writing to file
#save the HTML to a beautiful soup object
soup = BeautifulSoup(browser.page_source, 'html.parser')
#TODO: use breadcrumb of page name for loop later on
breadcrumb = soup.select('.breadcrumb span')
pagename = breadcrumb[0].get_text()
#open a file then write to it
bookPage = os.path.join('books/cpp/VST', pagename+'.txt')
open(pagename, 'wb')
pagename.write(str(soup))
#close file
#pagename.close()
#TODO: move on to next file