Strip HTML from strings in Python

前端 未结 26 2797
难免孤独
难免孤独 2020-11-22 02:50
from mechanize import Browser
br = Browser()
br.open(\'http://somewebpage\')
html = br.response().readlines()
for line in html:
  print line

When p

26条回答
  •  面向向阳花
    2020-11-22 03:10

    You can write your own function:

    def StripTags(text):
         finished = 0
         while not finished:
             finished = 1
             start = text.find("<")
             if start >= 0:
                 stop = text[start:].find(">")
                 if stop >= 0:
                     text = text[:start] + text[start+stop+1:]
                     finished = 0
         return text
    

提交回复
热议问题