-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscraping.py
62 lines (56 loc) · 2.75 KB
/
scraping.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
from lxml import html
import requests
import json
import argparse
from collections import OrderedDict
from bs4 import BeautifulSoup
nse_url = "https://www.moneycontrol.com/technical-analysis/indian-indices/nifty-50-9"
infy_url ='https://www.moneycontrol.com/technical-analysis/infosys/IT'
techm_url = 'https://www.moneycontrol.com/technical-analysis/techmahindra/TM4'
wipro_url = 'https://www.moneycontrol.com/technical-analysis/wipro/W'
adani_url = 'https://www.moneycontrol.com/technical-analysis/AdaniPorts/MPS'
cipla_url = 'https://www.moneycontrol.com/technical-analysis/cipla/C'
axis_bank_url = 'https://www.moneycontrol.com/technical-analysis/axisbank/AB16'
hcl_url = 'https://www.moneycontrol.com/technical-analysis/hcltechnologies/HCL02'
hdfc_url = 'https://www.moneycontrol.com/technical-analysis/hdfcbank/HDF01'
jswsteel_url = 'https://www.moneycontrol.com/technical-analysis/jswsteel/JSW01'
reliance_url = 'https://www.moneycontrol.com/technical-analysis/relianceindustries/RI'
upl_url = 'https://www.moneycontrol.com/technical-analysis/upl/UP04'
ongc_url= 'https://www.moneycontrol.com/technical-analysis/oilnaturalgascorporation/ONG'
hindun_url = 'https://www.moneycontrol.com/technical-analysis/hindustanunilever/HU'
itc_url = 'https://www.moneycontrol.com/technical-analysis/itc/ITC'
tcs_url = 'https://www.moneycontrol.com/technical-analysis/tataconsultancyservices/TCS'
company_dict = {
'NIFTY 50': nse_url,
'Axis': axis_bank_url,
'Cipla': cipla_url,
'HCL':hcl_url,
'HDFC Bank':hdfc_url,
'Hindustan Unilever': hindun_url,
'Infosys': infy_url,
'ITC': itc_url,
'JSW Steel': jswsteel_url,
'ONGC': ongc_url,
'Reliance': reliance_url,
'TATA Consultancy Services': tcs_url,
'Tech Mahindra': techm_url,
'UPL': upl_url,
'Wipro': wipro_url,
}
def get_rsi(company):
url = company_dict.get(company)
print("Key: {}, Company: {}".format(company, url))
response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')
rsi = soup.find_all('div', {'class':'mt20'})[3].find_all('td')[1].text
macd = soup.find_all('div', {'class':'mt20'})[3].find_all('td')[4].text
roc = soup.find_all('div', {'class':'mt20'})[3].find_all('td')[10].text
return rsi, macd, roc
def get_nse_rsi():
nse_url = "https://www.moneycontrol.com/technical-analysis/indian-indices/nifty-50-9"
response = requests.get(nse_url)
soup = BeautifulSoup(response.text, 'lxml')
rsi = soup.find_all('div', {'class':'mtindi FR'})[0].find('div', {'class':'mt20'}).find_all('td')[1].text
macd = soup.find_all('div', {'class':'mtindi FR'})[0].find('div', {'class':'mt20'}).find_all('td')[4].text
roc = soup.find_all('div', {'class':'mtindi FR'})[0].find('div', {'class':'mt20'}).find_all('td')[10].text
return rsi, macd, roc