-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStock_Scrapping_Selenium.py
More file actions
26 lines (23 loc) · 1.15 KB
/
Stock_Scrapping_Selenium.py
File metadata and controls
26 lines (23 loc) · 1.15 KB
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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
PATH= "C:\Program Files (x86)\chromedriver.exe"
driver=webdriver.Chrome(PATH)
def getStockValue(keyword):
driver.get("https://www.moneycontrol.com/india/stockpricequote/")
searchBox=driver.find_element_by_xpath('//*[@id="company"]')
searchBox.send_keys(keyword)
searchButton=driver.find_element_by_xpath('//*[@id="mc_mainWrapper"]/div[3]/div[1]/div[5]/form/div/input[2]')
searchButton.click()
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="div_nse_livebox_wrap"]/div[1]/div[1]/div/div[2]/span[1]'))
)
liveValue=driver.find_element_by_xpath('//*[@id="div_nse_livebox_wrap"]/div[1]/div[1]/div/div[2]/span[1]').text #Get value from NSE
finally:
print("Finally")
# searchBoxMain=driver.find_element_by_xpath('//*[@id="search_str"]')
# searchBoxMain.send_keys(text)
return liveValue
print(getStockValue('Axis Bank'))