-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBloomScraper.py
executable file
·34 lines (29 loc) · 1.05 KB
/
BloomScraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
import urllib2 # urllib2 is used to fetch url(s) via urlopen()
from bs4 import BeautifulSoup# when importing Beautiful Soup don't add 4.
from datetime import datetime # contains functions and classes for working with dates and times, separately and together
import argparse
def DEBUG():
return False
def get_symbol(_CHFEUR):
quote_page = 'https://www.bloomberg.com/quote/'+_CHFEUR+':CUR'
if DEBUG(): t1 = datetime.now()
page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page, "html.parser")
if DEBUG(): name_store = soup.find('div', attrs={'class' : 'ticker'})
if DEBUG(): name=name_store.text
price_store = soup.find('div', attrs={'class': 'price'})
price = price_store.text
if DEBUG(): t2 = datetime.now()
if DEBUG(): total = t2 -t1
return price
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--symbol', default="", help="symbol to fetch")
args = parser.parse_args()
###################################
s=args.symbol
res=get_symbol(str(s))
print res
if __name__ == '__main__':
main()