-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplay3.py
107 lines (99 loc) · 4.82 KB
/
Display3.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
from tkinter import *
import urllib.request
import urllib.parse
import urllib.error
from bs4 import BeautifulSoup
import ssl
import json
import ast
import os
from urllib.request import Request, urlopen
from pprint import pprint
def Display(url):
# For ignoring SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
# Making the website believe that you are accessing it using a Mozilla browser
req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
webpage = urlopen(req).read()
# Creating a BeautifulSoup object of the HTML page for easy extraction of data.
soup = BeautifulSoup(webpage, 'html.parser')
html = soup.prettify('utf-8')
company_json = {}
other_details = {}
for span in soup.findAll('span',
attrs={'class': 'Trsdu(0.3s) Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(b)'
}):
company_json['PRESENT_VALUE'] = span.text.strip()
for div in soup.findAll('div', attrs={'class': 'D(ib) Va(t)'}):
for span in div.findAll('span', recursive=False):
company_json['PRESENT_GROWTH'] = span.text.strip()
for td in soup.findAll('td', attrs={'data-test': 'PREV_CLOSE-value'}):
for span in td.findAll('span', recursive=False):
other_details['PREV_CLOSE'] = span.text.strip()
for td in soup.findAll('td', attrs={'data-test': 'OPEN-value'}):
for span in td.findAll('span', recursive=False):
other_details['OPEN'] = span.text.strip()
for td in soup.findAll('td', attrs={'data-test': 'BID-value'}):
for span in td.findAll('span', recursive=False):
other_details['BID'] = span.text.strip()
for td in soup.findAll('td', attrs={'data-test': 'ASK-value'}):
for span in td.findAll('span', recursive=False):
other_details['ASK'] = span.text.strip()
for td in soup.findAll('td', attrs={'data-test': 'DAYS_RANGE-value'}):
for span in td.findAll('span', recursive=False):
other_details['DAYS_RANGE'] = span.text.strip()
for td in soup.findAll('td',
attrs={'data-test': 'FIFTY_TWO_WK_RANGE-value'}):
for span in td.findAll('span', recursive=False):
other_details['FIFTY_TWO_WK_RANGE'] = span.text.strip()
for td in soup.findAll('td', attrs={'data-test': 'TD_VOLUME-value'}):
for span in td.findAll('span', recursive=False):
other_details['TD_VOLUME'] = span.text.strip()
for td in soup.findAll('td',
attrs={'data-test': 'AVERAGE_VOLUME_3MONTH-value'
}):
for span in td.findAll('span', recursive=False):
other_details['AVERAGE_VOLUME_3MONTH'] = span.text.strip()
for td in soup.findAll('td', attrs={'data-test': 'MARKET_CAP-value'}):
for span in td.findAll('span', recursive=False):
other_details['MARKET_CAP'] = span.text.strip()
for td in soup.findAll('td', attrs={'data-test': 'BETA_3Y-value'}):
for span in td.findAll('span', recursive=False):
other_details['BETA_3Y'] = span.text.strip()
for td in soup.findAll('td', attrs={'data-test': 'PE_RATIO-value'}):
for span in td.findAll('span', recursive=False):
other_details['PE_RATIO'] = span.text.strip()
for td in soup.findAll('td', attrs={'data-test': 'EPS_RATIO-value'}):
for span in td.findAll('span', recursive=False):
other_details['EPS_RATIO'] = span.text.strip()
for td in soup.findAll('td', attrs={'data-test': 'EARNINGS_DATE-value'
}):
other_details['EARNINGS_DATE'] = []
for span in td.findAll('span', recursive=False):
other_details['EARNINGS_DATE'].append(span.text.strip())
for td in soup.findAll('td',
attrs={'data-test': 'DIVIDEND_AND_YIELD-value'}):
other_details['DIVIDEND_AND_YIELD'] = td.text.strip()
for td in soup.findAll('td',
attrs={'data-test': 'EX_DIVIDEND_DATE-value'}):
for span in td.findAll('span', recursive=False):
other_details['EX_DIVIDEND_DATE'] = span.text.strip()
for td in soup.findAll('td',
attrs={'data-test': 'ONE_YEAR_TARGET_PRICE-value'
}):
for span in td.findAll('span', recursive=False):
other_details['ONE_YEAR_TARGET_PRICE'] = span.text.strip()
company_json['OTHER_DETAILS'] = other_details
with open('data.json', 'w') as outfile:
json.dump(company_json, outfile, indent=4)
Stock = open('data.json', "r")
root = Tk()
root.title("Stock Details Of Selected Company")
for data in Stock:
lbl = Label(root, text=data)
lbl.pack()
mainloop()