-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreener.py
136 lines (53 loc) · 2.49 KB
/
screener.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ChromeOptions
import time
def get_financials(bse_id):
options = webdriver.ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Chrome(options=options)
try:
website = "https://www.screener.in/company/" + bse_id + "/#quarters"
driver.get(website)
time.sleep(3)
rev_xpath = '//*[@id="quarters"]//table/tbody/tr[1]/td[position()=last()]'
r = driver.find_element(By.XPATH, rev_xpath)
a = r.get_attribute("innerText")
netp_xpath = '//*[@id="quarters"]//table/tbody/tr[10]/td[position()=last()]'
p = driver.find_element(By.XPATH, netp_xpath)
b = p.get_attribute("innerText")
market_cap ="//ul/li[1]/span[2]"
m = driver.find_element(By.XPATH , market_cap)
mc=m.get_attribute("innerText")
stock_pe="/html/body/main/div[3]/div[3]/div[2]/ul/li[4]/span[2]/span"
s=driver.find_element(By.XPATH, stock_pe)
sp=s.get_attribute("innerText")
#find out table size by for loop and then search for element
print("Current URL after search:", driver.current_url)
return a, b , mc,sp
except Exception as e:
print(f"An error occurred: {e}")
return "**", "**","**","**","**"
finally:
driver.quit()
def get_yr_reven(bse_id):
options = webdriver.ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Chrome(options=options)
try:
website = "https://www.screener.in/company/" + bse_id + "/#profit-loss"
driver.get(website)
time.sleep(3)
yr_reven='//*[@id="profit-loss"]//table/tbody/tr[1]/td[position()=last()-1]'
#/html/body/main/section[5]/div[2]/table/tbody/tr[1]
# /html/body/main/section[5]/div[3]/table/tbody/tr[1]/td[11]
y=driver.find_element(By.XPATH, yr_reven)
yr=y.get_attribute("innerText")
return yr
except Exception as e:
print(f"An error occurred: {e}")
return "**"
finally:
driver.quit()
#a,b,c,d=get_financials("539876")
#print(a,b,c,d)