-1

Hi here is my function:

def dictionary_search():
    from bs4 import BeautifulSoup
    from urllib.request import urlopen
    url = "http://dictionary.reference.com/browse/"+search_box.getText()+"?s=t"
    page = urlopen(url)
    soup = BeautifulSoup(page.read())
    defini = soup.find("div",{"class":"def-content"}).contents
    print(defini)

This is all part of a larger search engine my problem is that when I use print(defini). For example if my search was "dog" the result would be:

['\na domesticated canid, ', <span class="dbox-italic">Canis familiaris,</span>, ' bred in many varieties. ']

I would like to remove the excess info and just get the defintion.

Kijewski
  • 25,517
  • 12
  • 101
  • 143

1 Answers1

0
def dictionary_search():
    from bs4 import BeautifulSoup
    from urllib.request import urlopen
    url = "http://dictionary.reference.com/browse/"+search_box.getText()+"?s=t"
    page = urlopen(url)
    soup = BeautifulSoup(page.read())
    defini = soup.find("div",{"class":"def-content"}).text
    print(defini)

contents was taking everything including tags.