-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcompany_page.py
69 lines (53 loc) · 1.81 KB
/
company_page.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from try_module import trying as trying
class CompanyPage:
def __init__(self, tree):
self.tree = tree
def get_pe_ratio(self, tree):
pe_ratio = trying(tree, '//*[@id="div_rcard_more"]/div[1]/div[2]')
return pe_ratio
def get_eps(self, tree):
eps = trying(tree, '//*[@id="div_rcard_more"]/div[2]/div[2]')
return eps
def get_price_of_stock(self, tree):
pos = trying(tree, '//*[@id="ltpid"]')
return pos
def get_fifty_two_wk_high(self, tree):
return (
float(
tree.xpath('//*[@id="FiftyTwoHighlow"]/text()')[0]
.split()[0]
.replace(",", "")
)
)
def get_fifty_two_wk_low(self, tree):
return (
float(
tree.xpath('//*[@id="FiftyTwoHighlow"]/text()')[0]
.split()[-1]
.replace(",", "")
)
)
def _sheet_links(self, tree, this_xpath):
"""TODO: Docstring for _sheet_links.
:tree: TODO
:xpath: TODO
:returns: TODO
"""
try:
_sheet_links = tree.xpath(this_xpath)
_sheet_link = _sheet_links[0].attrib['href']
_sheet_link = _sheet_link.replace('//money', 'http://money')
except KeyError:
_sheet_link = ""
return _sheet_link
def get_balance_sheet_link(self, tree):
return self._sheet_links(tree, '//*[@id="div_res_centre_more"]/a[4]')
def get_ratio_link(self, tree):
return self._sheet_links(tree, '//*[@id="div_res_centre_more"]/a[11]')
def get_volume(self, tree):
"""TODO: Docstring for get_volume.
:tree: TODO
:returns: TODO
"""
volm = tree.xpath('//*[@id="Volume"]/text()')
return int(volm[0].replace(",", ""))