comment analyser le fichier ?[fermé]
-
21-12-2019 - |
Question
le code suivant analyse la chaîne.
import lxml.html
doc = lxml.html.document_fromstring("""<html>
<body>
<span class="simple_text">One</span> tehfghhxt</br>
<span class="cyrillic_text">Второй</span> cyrcyrcyr</br>
</body>
</html>
""")
txt1 = doc.xpath('/html/body/span[@class="simple_text"]/text()[1]')
print(txt1)
Je voudrais savoir comment analyser le fichier qui contient la même chaîne.et qui est dans le même répertoire.s'il vous plaît dites-moi.
La solution
string = open('file_with_string.html', 'r').read()
doc = lxml.html.document_fromstring(string)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow