Advertisement
Guest User

Untitled

a guest
Jun 6th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. class Stock():
  2.     def __init__(self, last, high, low, change):
  3.         self.last = last
  4.         self.high = high
  5.         self.low = low
  6.         self.change = change
  7.  
  8.     def __str__(self):
  9.         return 'Stock({}, {}, {}, {})'.format(
  10.                 last,
  11.                 high,
  12.                 low,
  13.                 change
  14.                 )
  15.  
  16. class Scrapper():
  17.  
  18.     def __init__(self, soup):
  19.         self.soup = soup
  20.  
  21.     def parse(self):
  22.  
  23.         # just making up names here
  24.         last = new_html.find('div', {'id' : 'qwidget_lastsale'})
  25.         high = new_html.find('div', {'class' : 'qwidget-symbol'})
  26.         low = new_html.find('div', {'id' : 'qwidget_netchange'})
  27.         change = new_html.find('div', {'id' : 'qwidget_percent'})
  28.  
  29.         return Stock(last, high, low, change)
  30.  
  31.  
  32. class AppleScrapper(Scraper):
  33.     def parse(self):
  34.         # handles a different kind of scrapping
  35.         last = new_html.find('div', {'id' : 'qwidget_lastsale'})
  36.         #high = new_html.find('div', {'class' : 'qwidget-symbol'})
  37.         low = new_html.find('div', {'id' : 'qwidget_netchange'})
  38.         change = new_html.find('div', {'id' : 'qwidget_percent'})
  39.  
  40.         return Stock(last, None, low, change)
  41.  
  42.  
  43.  
  44. def get_info_google():
  45.     raw_html = simple_get('https://www.nasdaq.com/symbol/goog/real-time')
  46.     new_html = bs(raw_html, 'html.parser')
  47.     scraper = Scraper(new_html))
  48.     print(scraper.parse())
  49.  
  50. def get_generic(symbol, scrapper_class):
  51.     url = 'https://www.nasdaq.com/symbol/{}/real-time'.format(symbol)
  52.  
  53.     raw_html = simple_get(url)
  54.     new_html = bs(raw_html, 'html.parser')
  55.     scraper = scrapper_class(new_html))
  56.     return scraper.parse()
  57.  
  58. def get_apple():
  59.     stock = get_generic('appl', AppleScraper)
  60.     print(stock)
  61.     print(scraper.parse())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement