forked from soumilshah1995/hacking-API-from-website-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoldRateIndia.py
46 lines (34 loc) · 1.27 KB
/
goldRateIndia.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
try:
import requests
from bs4 import BeautifulSoup
except Exception as e:
print('Some Modules are Missing {}'.formate(e))
class Goldrate(object):
def __init__(self):
self.__headers = {
'Accept-Encoding': 'gzip, deflate, sdch',
'Accept-Language': 'en-US,en;q=0.8',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Referer': 'http://www.wikipedia.org/',
'Connection': 'keep-alive',
}
self.url = " https://www.paisabazaar.com/gold-rate/"
@property
def get(self):
"""
:return: String value for Gold Rates
"""
r = requests.get(url=self.url, headers=self.__headers)
soup = BeautifulSoup(r.text, 'html.parser')
data = soup.findAll(class_='g-6-s goldRate__price goldRatePriceHighLite')
tem = []
for x in data:
val = x.text[3:]
tem.append(val)
break
return tem[0]
if __name__ == "__main__":
obj = Goldrate()
data = obj.get
print("Soumil Gold Rates in India :\t{}".format(data))