Strip HTML from strings in Python

前端 未结 26 2641
难免孤独
难免孤独 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:16

    I have used Eloff's answer successfully for Python 3.1 [many thanks!].

    I upgraded to Python 3.2.3, and ran into errors.

    The solution, provided here thanks to the responder Thomas K, is to insert super().__init__() into the following code:

    def __init__(self):
        self.reset()
        self.fed = []
    

    ... in order to make it look like this:

    def __init__(self):
        super().__init__()
        self.reset()
        self.fed = []
    

    ... and it will work for Python 3.2.3.

    Again, thanks to Thomas K for the fix and for Eloff's original code provided above!

提交回复
热议问题