Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 4th, 2005, 12:30 PM   #1
SaturN
Programmer
 
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4 SaturN is on a distinguished road
Question Reading from web page??

I'm trying to make a script that will search google, for a users input, and return the results, but i don't want all the html coding etc etc that comes with it!! Can anyone give me advice on removing this!! At the moment, i just save the results to a new html file, that can then be viewed, as the website is viewed!!
Anyideas anyone??
Also, what's a good program for doing gui in python?? i've got tkinter, but i can't seem to get it to work i don't think the files have been stored in the right dir or something, so i'm useless really ain't I!! Thanks for any help in advance, it's prob a really easy task to do, i just can't seem to figure it out!
I've tried, .strip(<HTML> <BODY> blah blah blah) but that gets very excessive, and returns odd looking text!!
Any way!!
Thanks
__________________
while me is alive:
	make(life,simple)
SaturN is offline   Reply With Quote
Old Jul 4th, 2005, 12:40 PM   #2
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Google has a search api you could use...
http://www.google.com/apis/
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Jul 4th, 2005, 3:41 PM   #3
SaturN
Programmer
 
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4 SaturN is on a distinguished road
your a bit of a star ain't ya
lol, thanks
atm i'm gonna use it like
import urllib2, os, sys, random
from time import sleep

path = "C:\Lyrics"
print """
=================================================
=          SaturN Lyric Search Console          =
=================================================
Enter 'quit' as search command to exit console
When you quit, you can flush all searches!
"""
print "Loading" ,str(random.randint(0,11)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randint(11,21)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randint(21,31)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randrange(31,41)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randrange(41,51)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randrange(51,61)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randrange(61,71)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randrange(71,81)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randrange(91,98)) + '% complete'
sleep(0.5)
print "100% complete"

print "Lyrics Will Be Stored In %s"% (path)
def Main():
    if "Lyrics" not in os.listdir("C:\\"):
        os.mkdir(path)    
    search = []
    word = raw_input("\n\n\n\nEnter your search using either..\nArtits\nSong\nLyrics\nTo search\n>>:  ")
    if word.lower() == 'quit':
        End()
        sys.exit()
    for a in word:
        if a == ' ':
            search.append('+')
        else:
            search.append(a)
    search = "".join(search)
    url = """http://search.azlyrics.com/cgi-bin/azseek.cgi?q=%s""" % (search)
    opener = urllib2.build_opener()
    opener.addheaders = [('User-agent', 'Mozilla/5.0')]
    try:
        lyrics = opener.open(url).read()
        file = open("%s\%s.html" % (path, search),'w')
        file.write(lyrics)
        os.startfile("%s\%s.html"% (path, search))
        file.close()
    except:
        IOError
        print "Unable To Open - \nLoading to research"
    Main()

def End():
    print """
Thanks for using Saturn Lyric Finder, powered by 'azseek'
*************@hotmail.com
"""
    a = raw_input("Would You Like To Flush Searchs? (Y/N) ")
    if a.lower() == "y":
        for file in os.listdir(path):
            os.remove(os.path.join(path, file))
            print "%s has been removed"% (file)
            raw_input("Enter To Quit!\n")
    if a.lower() == 'n':
        raw_input("Enter To Quit\n")
    
Main()

untill i can use sockets in the best possible manor!!
thanks for that api, may come in handy soon!
__________________
while me is alive:
	make(life,simple)
SaturN is offline   Reply With Quote
Old Jul 4th, 2005, 6:15 PM   #4
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
If you're searching for lyrics, feel free to have a look at or make use of a Python module I made that does so via http://lyrc.com.ar (which allows you to freely search their lyrics database). Searching azlyrics is of debatable legality if i'm not mistaken...
Cerulean is offline   Reply With Quote
Old Jul 4th, 2005, 7:16 PM   #5
SaturN
Programmer
 
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4 SaturN is on a distinguished road
Ahhh, legality!! hmmm, forgot about that!! thanks!! i've changed the code, but i actually like the idea of having the html's save so i've kept that
new code will be updated asap
__________________
while me is alive:
	make(life,simple)
SaturN is offline   Reply With Quote
Old Jul 4th, 2005, 7:28 PM   #6
SaturN
Programmer
 
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4 SaturN is on a distinguished road
ok it won't let me edit my coded post...
so i'm gonna have to do it here..
New Code..
import urllib2, os, sys, random
from time import sleep
path = "C:\Lyrics"
print """
=================================================
=		  SaturN Lyric Search Console		  =
=================================================
Enter 'quit' as search command to exit console
When you quit, you can flush all searches!
"""
print "Loading" ,str(random.randint(0,11)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randint(11,21)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randint(21,31)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randrange(31,41)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randrange(41,51)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randrange(51,61)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randrange(61,71)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randrange(71,81)) + '% complete'
sleep(0.5)
print "Loading" ,str(random.randrange(91,98)) + '% complete'
sleep(0.5)
print "100% complete"
print "Lyrics Will Be Stored In %s"% (path)
def Main():
	if "Lyrics" not in os.listdir("C:\\"):
		os.mkdir(path)	
	artist = raw_input("\nType quit here to exit\nArtist:>> ")
	if artist.lower() == "quit":
		End()
		sys.exit()
	song = raw_input("\nSong Title:>> ")
	song = song.replace(" ","%20")
	artist = artist.replace(" ","%20")
	url = """http://lyrc.com.ar/en/tema1en.php?songname=%s&artist=%s""" % (song,artist)
	opener = urllib2.build_opener()
	opener.addheaders = [('User-agent', 'Mozilla/5.0')]
	lyrics = opener.open(url).read()
	artist = artist.replace("%20","_")
	song = song.replace("%20","_")
	file = open("%s\%s.html" % (path, "%s by %s"%(song, artist)),'w')
	file.write(lyrics)
	os.startfile("%s\%s.html"% (path, "%s by %s"% (song, artist)))
	file.close()
	Main()
def End():
	print """
Thanks for using Saturn Lyric Finder
fixationtohell@hotmail.com
"""
	a = raw_input("Would You Like To Flush Searchs? (Y/N) ")
	if a.lower() == "y":
		for file in os.listdir(path):
			os.remove(os.path.join(path, file))
			print "%s has been removed"% (file)
			raw_input("Enter To Quit!\n")
	if a.lower() == 'n':
		raw_input("Enter To Quit\n")
	
Main()

there we go lol

Last edited by SaturN; Jul 4th, 2005 at 7:30 PM. Reason: :$ i'm useless lol
SaturN is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:20 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC