0

I am trying to read a text file using python and getting the contents of the data from that file, and write it to an HTML webpage. I have no issues reading the file and storing the desired string in Python, the issue comes when trying to pass that stored string in HTML to write to the webpage. Below is the python code to get the desired string from the text file that stores it in 'desired_string.'

d = open('d', 'r')
for line in d:
 desired_string = line

Next, I want to write this 'desired_string' to a webpage using HTML (same file as python code). The issue is that when I use the code below, all that is happening is 'desired_string' is getting printed out and not the contents of desired_string.

<p>desired_string</p>
user367640
  • 31
  • 5

1 Answers1

-2

Have you tried using BeautifulSoup?

from bs4 import BeautifulSoup
soup = BeautifulSoup(text_file_content, 'html.parser')

After this please use the find/find_all methods, and after reaching this paragraph, use the method:

my_paragraph.text
JammingThebBits
  • 732
  • 11
  • 31