A question. It is necessary to indicate in the file name an identical link name, for example, β http://news.bbc.co.uk/2/hi/health/2284783.stm β. How do I specify slashes? As I understand it, you can do something with the encoding, but I still do not understand how to do it. The file name should look like this " http://news.bbc.co.uk/2/hi/health/2284783.txt ". The file extension can be β.docβ or any other text editor.
import urllib.request import bs4 from bs4 import BeautifulSoup import os import html2text class Pars (): #'http://news.bbc.co.uk/2/hi/health/2284783.stm' def __init__(self, url): self.text = url #print ('//////Text///////',self.text) self.s = urllib.request.urlopen(self.text).read() #https://pythonworld.ru/osnovy/faq.html #https://amdm.ru/akkordi/maks_korzh/102669/v_temnote/ soup = BeautifulSoup (self.s, features='html.parser') for script in soup(['script', 'style']): script.extract() self.html_text = str(html2text.HTML2Text().handle(soup.text)) #print (html_text) print (self.html_text) class Write (Pars): #print ('text') def WriteFile (self): self.text = str(self.text) #print ('test', self.text) self.html_text = str(self.html_text) #print ('SELF.HTML_TEXT', self.html_text) name_file_1 = self.text.replace(':', '+') name_file_1 = name_file_1.replace ('/', '_') name_file_2 = os.path.splitext (name_file_1)[0] + '.doc' print ('Name you file', '\n', name_file_2) file = open (name_file_2, 'w') print ('And path', '\n', os.path.abspath (name_file_2)) file.write (str(self.html_text)) #print ('test') url = input() Job_Pars = Pars(url) Job_Write = Write(url) Job_Write.WriteFile()