Forums

Problem with delimiters and html tags

hello, I have this delimiter, this selects the content of <title> I go home </title> tag,

This is the delimiters:

delimitatori_text_exterior_articol = [['<title','</title>']] WORKS GREAT

Now, I want to change the <title> tag with a meta tag, for example:

delimitatori_text_exterior_articol = [['<meta name="description" content="','"/>']] This will select the content of the meta description tag.

The Problem is that I don't know why is working with <title> tag and does not working with <meta description> tag

PyScripter runs the code successfully, with both tags, but doesn't change anything on my file if I change <title> tag with the <meta description> tag

You have below the code with the delimiter code.

#delimitatori_text_exterior_articol = [['<title','</title>']]
delimitatori_text_exterior_articol = [['<meta name="description" content="','"/>']]

def selectare_text():
    for file in os.listdir(fisiere_din_folder):
        if file.endswith(extensie_fisier):
            lista_cale_fisiere.append(os.path.join(fisiere_din_folder, file))

    for fisier in lista_cale_fisiere:

        f = open(fisier, 'r')

        if f.mode == 'r':
            contents = f.read()
            #contents = html.unescape(contents)      # Convert all named and numeric character references (e.g. &gt;, &#62;, &#x3e;) in the string s to the corresponding Unicode characters.
            print ("Acum lucrez la fisierul :", fisier)

            continut = []
            if (contents.find('<!-- ARTICOL START -->')>0):       # am gasit '<!-- ARTICOL START -->' in pagina
                poz1 = contents.find('<!-- ARTICOL START -->') + len('<!-- ARTICOL START -->')
                poz2 = contents.find('<!-- ARTICOL FINAL -->') + len('<!-- ARTICOL FINAL -->')
                inceput = contents[:poz1]
                articol = contents[poz1:poz2]
                final = contents[poz2:]
                continut.append(inceput)
                continut.append(articol)
                continut.append(final)
            else:
                continut.append(contents)
            continut_tradus = ''
            if (len(continut) == 3):
                continut_tradus = continut_tradus + selectare_traducere_continut(continut[0], delimitatori_text_exterior_articol) # inceput
                continut_tradus = continut_tradus + selectare_traducere_continut(continut[1], delimitatori_text_interior_articol) # articol
                continut_tradus = continut_tradus + selectare_traducere_continut(continut[2], delimitatori_text_exterior_articol) # exterior
            elif (len(continut) == 1):
                continut_tradus = continut_tradus + selectare_traducere_continut(continut[0], delimitatori_text_exterior_articol)
            else:
                print ("S-a produs o eroare cand am vrut sa citesc articolul sau exteriorul lui !")
        print("Am citit un fisier si incep traducerea!\n")

These are the forums for PythonAnywhere, an online Python development and hosting environment. While other users of our site might be able to help you out with problems you're having developing something on your own machine, you might have better luck getting an answer to a general programming problem at a programming Q&A site like Stack Overflow.