How to detect with python if the string contains html code?

后端 未结 4 585
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 21:44

How to detect either the string contains an html (can be html4, html5, just partials of html within text)? I do not need a version of HTML, but rather if the string is just

4条回答
  •  再見小時候
    2020-12-29 22:34

    Expanding on the previous post I would do something like this for something quick and simple:

    import sys, os
    
    if os.path.exists("file.html"):
        checkfile=open("file.html", mode="r", encoding="utf-8")
        ishtml = False
        for line in checkfile:
            line=line.strip()
            if line == ""
                ishtml = True
        if ishtml:
            print("This is an html file")
        else:
            print("This is not an html file")
    

提交回复
热议问题