From the course: Build Three Real-World Python Applications

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

How to write HTML code to a text file

How to write HTML code to a text file - Python Tutorial

From the course: Build Three Real-World Python Applications

How to write HTML code to a text file

- [Instructor] To wrap up this chapter we will export our scraped HTML code into a text file. There are multiple ways to do this but we will show the following way of how to send information to a text file. We begin by opening our text file by typing in with and open. And then we need to name our text file. I'm going to name my text file Wisdom vet.txt but you are welcome to name your file something else. Just make sure you have the .txt at the end of it. Then we add a comma and we add the letter W and that shows that we want to write something to this file. If we get out of these parentheses, we will type in as f and this will allow us to name our new file function F. We'll go to the next line. Make sure you indent in. We're going to type in our variable F and a period and then we want to do our write function and we are going to write our soup.prettify and add parentheses. So this will write our soup variable in…

Contents