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>
3
  • doesn't seem to work. Commented Jun 17, 2021 at 20:35
  • Why not? What happened? Commented Jun 17, 2021 at 20:40
  • nevermind it works! Commented Jun 17, 2021 at 21:00

1 Answer 1

-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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.