EG Information
Training Missions
Knowledge Bank
Pimp Us Out!
Has Enigma Group Helped You? Then Help Us By Advertising For Us. Place One Of The Following Images On Your Site And Create A Link Back To Enigma Group.
|
| |
|
|
Enigma Group's Code Bank
Python DictionaryBy: Futility - Date Submitted: 2009-05-11 17:59:57 #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #Takes a list of words from a specified file, runs them # through dictionary.com and prints the definitions in a # new text document. Very useful for when your teacher # wants to give you homework, but there's nothing left # to assign, so she makes you copy 127 definitions from # the back of the book due the next day making you realize # what a waste of time the class is so you just make this # program instead... Anyway, here it is. # #Note: Only takes the first definition from each search. You can easily # change this by making it look for 2.</td><td> rather than 1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- import urllib2 #imports urllib2... can't get much simpler than that print '--------------------------------------------------------------------------' print 'Hello and welcome to my dictionary program. In order to use it, you must' print 'create a text file in the same directory as the program. In the text file,' print 'you have to make a list of words you need to be defined, but' print 'make sure they\'re each on a new line or it won\'t work. The script then runs' print 'through the list and places each word into a search on dictionary.com.' print 'It then copies the definitions and saves them into the specified file.' print ' Enjoy' print print 'Created By: Futility' print 'Written In: Python' print '--------------------------------------------------------------------------' print saveTo = raw_input("What would you like the output file to be named? (Be sure to include the .txt)\n") DefFile = open(saveTo,"w") #Opens the file where the definitions will be saved wordlist = raw_input("What text file will the words be located in? (Once again, .txt is important)\n") f = open(wordlist) #Opens the file where the words are for line in f: #starts the loop that'll read through your list of words page = urllib2.urlopen('http://dictionary.reference.com/browse/' + line) #opens the dictionary.com page for your words html = page.read() #saves the source of the opened page #Get the definition pos = html.find('1.</td> <td>')#Find where you need to start from the source definition = html[pos+12:]#Cut out all the unnecessary tags endpos = definition.find('<')#Define the end position as the start of a new tag definition = definition[:endpos]#Combine the start and stop to get the full definition DefFile.write(line + definition + '\n\n')#Write the definition to the file with two newlines for formatting purposes print 'Congratulations, you\'re done. Check ' + saveTo + ' for all your new definitions.' print ' You\'re Welcome.' #Close the files. Not really necessary, but I do it anyway. f.close() DefFile.close()
|
| Return to
python category list |
|
|
Who Visited EnigmaGroup Today?
1647 Guests, 147 Users (157 Spiders)
milindsalvlve, todearshan, Evil1, ravikiranh, diabolo94, Anonanonamous, f0gh0rn, gohmushroom, itsukiminami2, Anonymousfigure, ellisp, untchable, Nemoxias, dnoz78, tehuringa, tulu, akhil, Abhinav2107, st3alth, ktsukino, riker987, ropopopo, maddy, ExpDel, D3ath, haidedesu, yentup, neuron, so0bi34, rinkiyoshikinjo, Moff, kaucha, Nightraven, Peid0, mOI, Arsenal, cosmo, GothicLogic, leonheart, Heugal, NoPc, Ausome1, bbml, Red, gigajum, cls777, dark_void, Megji, Devio, Marko Bijelic, zombiehack640, wx3gamer, jimmy1693, Alberto, Zylinx™, timthemale, Farrella1, proman, edeck, 9r4n+on, suplolx, cor3dump, Padraig.Nolan, seichi, asm0daios, c0d3br4wl3r, lam_zodiac, Wade, KidNinja, Futility, fatal, echo_steps, vinmen, xsiemich, potato18, Maleus, dpd29, y2k_2000, babinem, MBoomer, N4g4c3N, Bahamut, falber, Raell, nocow4bob, statix, Mr Pacifist, pqouewhsldghlsg, kaitou_kid, xthomd, lucca65, giovanni, sanjaydeshmukh380, Ghosterr, Ton That Vinh, JaRam, Medeoker, Jesser, delta30, psychomarine, dark_executer, nSoul, raybendegun, vipro, jbrown, harsh419heavy, CrashOverron, dagey, vishnu koppala, AcidAvenger, pquake, voodooKobra, Annumbo, Null Set, Doraga, panda_hacker, qty92, eusouumpeixe, obm0rok, Unlift, basti, Simad, Owlclaw, mahesh, Garfik666, hackaday, matewan, c0re, Arkz.Ruby, Craylien, ApexGfx, Mr.McCoy, intersys, musamanyama, unknown1346, edwin092, mgkorman, Rex_Mundi, VonGuntherz, lol, Dude2, Adelaido, hacksaw24, Synick, £ûpletcherer¡¡¡|h¡¡., Arc, prabhu |
| |
|
|
|
|
|