Hello 🙂 After playing around for a bit, I’ve come up with the following function, which returns the full HTML tag, rather than simply the part in inverted <>”this”<>
from BeautifulSoup import BeautifulSoup
from urllib2 import urlopen
def get_wotd():
return str((BeautifulSoup(urlopen('http://www.reference.com/wordoftheday'))).findAll('h2'))
print get_wotd()
Today’s word, for instance is “nosh”. Instead of getting:
[<h2 class="me">nosh</h2>]
I need the output to be, simply,
nosh
Anyone got any idea how I could pull this off?
Use
.textattribute to fetch inner-text, and usefind()method instead: