Hi everyone,
This is my first time here, so if I don't do everything up to how it should be done, bear with me. Anyways, for a project in my python class I am having trouble generating a webpage with clickable links. I am using Python 2.6.5 and will be eventually hosting this on Google's AppSpot.
Anyways, let me just say this: Programming is really hard for me. I don't know what it is, but I can't put what I am thinking into code. So although these questions may seem simple, it's not because I am not trying, it's because they are just hard for me to understand.
So, here is my code so far:
import urllib2
from BeautifulSoup import BeautifulSoup
def mainPage():
s='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\n'
s +='"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"\n'
s +='<html><head>\n'
s +='<title>At-A-Glance Stock Information</title>\n'
#s +="<link rel='stylesheet' href='mystyles.css' type='text/css' />\n"
s +='</head>\n'
s +='<body>\n'
s +='<a href = http://www.speedfinance.appspot.com/sprint>Sprint</a>\n'
s +='<a href = http://www.speedfinance.appspot.com/google>Google</a>\n'
s +='<a href = http://www.speedfinance.appspot.com/apple>Apple</a>\n'
s +='<a href = http://www.speedfinance.appspot.com/att>AT&T</a>\n'
s +='<a href = http://www.speedfinance.appspot.com/microsoft>Microsoft</a>\n'
return s
for name in company:
generateMainPage(company
def generateMainPage(company, url):
company = ['sprint', 'google', 'apple', 'att', 'microsoft']
companyUrl = ['/sprint', '/google', '/apple', '/att', '/microsoft']
s='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\n'
s +='"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"\n'
s +='<html><head>\n'
s +='<title>At-A-Glance Stock Information</title>\n'
#s +="<link rel='stylesheet' href='mystyles.css' type='text/css' />\n"
s +='</head>\n'
s +='<body>\n'
s +='<a href =' + link + '>'+company+'</a>\n'
return s
def sprint():
website = 'http://www.google.com/finance/company_news?q=NYSE:S'
articles = urllib2.urlopen(website).read()
soup = BeautifulSoup(articles,selfClosingTags = ["br"])
stories = []
for entry in soup.findAll('div', attrs = "g-section news sfe-break-bottom-16", limit = 4):
link = str(entry.find("a")["href"])
print link
sprint()
def google():
website = 'http://www.google.com/finance/company_news?q=NASDAQ:GOOG'
articles = urllib2.urlopen(website).read()
soup = BeautifulSoup(articles,selfClosingTags = ["br"])
stories = []
for entry in soup.findAll('div', attrs = "g-section news sfe-break-bottom-16", limit = 4):
link = str(entry.find("a")["href"])
print link
google()
def apple():
website = 'http://www.google.com/finance/company_news?q=NASDAQ:AAPL'
articles = urllib2.urlopen(website).read()
soup = BeautifulSoup(articles,selfClosingTags = ["br"])
stories = []
for entry in soup.findAll('div', attrs = "g-section news sfe-break-bottom-16", limit = 4):
link = str(entry.find("a")["href"])
print link
apple()
def att():
website = 'http://www.google.com/finance/company_news?q=NYSE:ATT'
articles = urllib2.urlopen(website).read()
soup = BeautifulSoup(articles,selfClosingTags = ["br"])
stories = []
for entry in soup.findAll('div', attrs = "g-section news sfe-break-bottom-16", limit = 4):
link = str(entry.find("a")["href"])
print link
att()
def microsoft():
website = 'http://www.google.com/finance/company_news?q=NASDAQ:MSFT'
articles = urllib2.urlopen(website).read()
soup = BeautifulSoup(articles,selfClosingTags = ["br"])
stories = []
for entry in soup.findAll('div', attrs = "g-section news sfe-break-bottom-16", limit = 4):
link = str(entry.find("a")["href"])
print link
microsoft()
generateMainPage and mainPage are basically the same idea I am trying to implement. In words, I am trying to make each company have a clickable link on the homepage that will direct to another page and (currently) show the url's to the top news stories for those companies. However, I am having troubles making it work that way.
Also, I know my code is really messy, but I am in the general set-up phase.