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() 
  • No The file name can not be a slash - Alexey Ten
  • Here, look, then they did it somehow and even seemed to explain how, but I don't understand - Decya
  • There are no slashes, but, most likely, a division symbol. In any case, better tell me what the problem you are solving and why did you need slashes? - Alexey Ten
  • I do the parsing of sites (any one site that I enter from the keyboard), then I write the data to a file. Then I need to give a name to the file. For example: if the link was β€œ news.bbc.co.uk/2/hi/health/2284783.stm ”, then the file name should be β€œ news.bbc.co.uk/2/hi/health/2284783.txt . As you can see, only the extension has changed, so that the file can be opened in the editor. - Decya

0