mercredi 25 mars 2015

how save output from python to database?

I wrote a simple script for translation in urbandictionary:



import urllib.request
import bs4

def translate():
search=''
while(search!='!'):
search=input("Enter a word(! for exit): ")
if search=='!':
continue
search2=search.replace(' ','+')
urb_url='http://ift.tt/I7sQKf'+str(search2)
urban=urllib.request.urlopen(urb_url).read().decode('utf-8')
soup_urb = bs4.BeautifulSoup(urban)
try:
q2=soup_urb.find('div', class_="meaning").text
print("{0}: {1}".format(search,q2))
except AttributeError as e:
print("The word not found\n")


now I want to save result for every word that searched to use and don't search again in the future. what is your suggestion? sqlite, save in simple text or other solutions.


Aucun commentaire:

Enregistrer un commentaire