Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 read text file and write into html with correct link
#1
Do anyone know how to read a file, and write into html with the correct link page.

i have a file name test.txt, which contain:
http://www.google.com
http://www.cnn.com

If i write as below, it will not link to correct link page. Do anyone know why? What shall i correct, if i want to link correct place.

with open('test.txt') as f,open('out.html', 'w') as f_out:
    for line in f:
        line = line.strip()
        
        #print("<a href=",line ,"</a>","link")
        #print (line1)
       
        f_out.write('{}<br>'.format('<a href="line">Link </a>'))
        
        hyperlink_format = '<a href="{link}">{text}</a>'
        
	
How to i let it display on html which will have this two link.

i also try with this
f_out.write('{}<br>'.format('<a href="+line+">Link </a>'))
same
Quote
#2
Hello,

Try

with open('test.txt') as f,open('out.html', 'w') as f_out:
    for line in f:
        line = line.strip()
         
        #print("<a href=",line ,"</a>","link")
        #print (line1)
        
        f_out.write('{}<br>'.format('<a href="' + line + '">Link ' + line + '</a>'))
         
        hyperlink_format = '<a href="{link}">{text}</a>'
Nicolas TATARENKO
Quote
#3
hi avorane,
thanks it work.
Quote
#4
hi avorane,
i have one question why i press the link it won't link direct to http://www.google.com, it link file:///C:/read_file/www.google.com.
do you know where to change
Quote
#5
i know what's the problem, if the text file contain http:// will work, but if you put without https:// will occur file:///C:/read_file/www.google.com.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Write SQLite query result to file hjk6734 1 61 May-27-2020, 12:17 PM
Last Post: menator01
  Read Multiples Text Files get specific lines based criteria zinho 5 241 May-19-2020, 12:30 PM
Last Post: zinho
  Append JSON's and write to file faqsap 4 177 May-15-2020, 04:20 PM
Last Post: faqsap
  Read excel file to determine the rules abc12345 4 275 May-13-2020, 12:59 PM
Last Post: abc12345
  How to read file inside class Mekala 11 344 May-02-2020, 11:36 AM
Last Post: snippsat
  Read content of GitHub file sridhar 5 219 Apr-29-2020, 11:49 PM
Last Post: sridhar
  Making .exe file that requires access to text and html files ClassicalSoul 0 83 Apr-23-2020, 05:03 PM
Last Post: ClassicalSoul
  Read a CSV file only from the 4th line/row asaforen7 8 419 Apr-16-2020, 01:49 AM
Last Post: Larz60+
  Read and save file in chucksize zinho 3 209 Apr-02-2020, 08:12 AM
Last Post: DeaD_EyE
  Print/write to file function tpolim008 4 216 Apr-01-2020, 07:59 PM
Last Post: tpolim008

Forum Jump:


Users browsing this thread: 1 Guest(s)