-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbsoup.py
executable file
·53 lines (37 loc) · 1.23 KB
/
bsoup.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
from bs4 import BeautifulSoup
import urllib
riskURL = "https://finance.yahoo.com/quote/SHSAX/risk"
page = urllib.urlopen(riskURL)
content = page.read().decode('utf-8')
soup = BeautifulSoup(content, 'html.parser')
#import pdb; pdb.set_trace()
std=[]
std_span = next(x for x in soup.find_all('span') if x.text == "Standard Deviation")
parent_div = std_span.parent
for sibling in parent_div.next_siblings:
for child in sibling.children:
# do something
#print(child.text)
std.append((child.text).encode("utf-8"))
print std
print '--------------------'
alpha=[]
alpha_span = next(x for x in soup.find_all('span') if x.text == "Alpha")
parent_div = alpha_span.parent
for sibling in parent_div.next_siblings:
for child in sibling.children:
# do something
#print(child.text)
alpha.append((child.text).encode("utf-8"))
print alpha
print '--------------------'
beta=[]
beta_span = next(x for x in soup.find_all('span') if x.text == "Beta")
parent_div = beta_span.parent
for sibling in parent_div.next_siblings:
for child in sibling.children:
# do something
#print(child.text)
beta.append((child.text).encode("utf-8"))
print beta