Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Stock():
- def __init__(self, last, high, low, change):
- self.last = last
- self.high = high
- self.low = low
- self.change = change
- def __str__(self):
- return 'Stock({}, {}, {}, {})'.format(
- last,
- high,
- low,
- change
- )
- class Scrapper():
- def __init__(self, soup):
- self.soup = soup
- def parse(self):
- # just making up names here
- last = new_html.find('div', {'id' : 'qwidget_lastsale'})
- high = new_html.find('div', {'class' : 'qwidget-symbol'})
- low = new_html.find('div', {'id' : 'qwidget_netchange'})
- change = new_html.find('div', {'id' : 'qwidget_percent'})
- return Stock(last, high, low, change)
- class AppleScrapper(Scraper):
- def parse(self):
- # handles a different kind of scrapping
- last = new_html.find('div', {'id' : 'qwidget_lastsale'})
- #high = new_html.find('div', {'class' : 'qwidget-symbol'})
- low = new_html.find('div', {'id' : 'qwidget_netchange'})
- change = new_html.find('div', {'id' : 'qwidget_percent'})
- return Stock(last, None, low, change)
- def get_info_google():
- raw_html = simple_get('https://www.nasdaq.com/symbol/goog/real-time')
- new_html = bs(raw_html, 'html.parser')
- scraper = Scraper(new_html))
- print(scraper.parse())
- def get_generic(symbol, scrapper_class):
- url = 'https://www.nasdaq.com/symbol/{}/real-time'.format(symbol)
- raw_html = simple_get(url)
- new_html = bs(raw_html, 'html.parser')
- scraper = scrapper_class(new_html))
- return scraper.parse()
- def get_apple():
- stock = get_generic('appl', AppleScraper)
- print(stock)
- print(scraper.parse())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement