First off what I am trying to do is ask the user for a search term. The program then searches yahoo and prints out the link of the first result. Here's the code I have so far.
from urllib import urlopen
import re, time
from BeautifulSoup import BeautifulSoup
print "What Would You Like to Search For?"
user_input = raw_input('') #Gets Search Term from User
search = "http://search.yahoo.com/search;_ylt=A2KLtaJX_1BQfT4AwX2bvZx4?p=baker&toggle=1&cop=mss&ei=UTF-8&fr=yfp-t-701"
new_search = search.replace('baker', user_input)
content = urlopen( new_search ).read()
soupcontent = BeautifulSoup(content)
link1 = soupcontent.find(id="link-1")
print link1
Everything works fine. It takes the user input and searches Yahoo. The problem I'm having is lets say I searched for 'dog'
the program would then print something like this: "a id="link-1" class="yschttl spt" href="http://www.dog.com/" data-bk="5101.1>b>Dog/b> Supplies | b>Dog/b> Food, b>Dog/b> Beds, b>Dog/b> wbr>/wbr>Flea Control & More .../a>"
Which Is indeed the first Link on the page. However I would only like it to print out "http://www.dog.com/" Can anyone help me with this?
Thanks.