Skip to content Skip to sidebar Skip to footer

Extract Text From Html File With Beautifulsoup/python

I am trying to extract the text from a html file. The html file looks like this:
  • Copy

    Returns:

    Baden-Württemberg
    Bayern
    Berlin
    

    The builtin python dir() and type() methods are always handy to inspect an object.

    print(dir(names))
    
    [...,
     '__sizeof__',
     '__str__',
     '__subclasshook__',
     '__weakref__',
     'append',
     'clear',
     'copy',
     'count',
     'extend',
     'index',
     'insert',
     'pop',
     'remove',
     'reverse',
     'sort',
     'source']
    
  • Solution 2:

    With a list of comprehension you could do the following :

    names = soup.find_all("span",{"class":"toctext"})
    print([x.text for x in names])
    

    Post a Comment for "Extract Text From Html File With Beautifulsoup/python"