-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape.py
More file actions
44 lines (41 loc) · 1.37 KB
/
scrape.py
File metadata and controls
44 lines (41 loc) · 1.37 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from bs4 import BeautifulSoup
import requests
print ("Which company would you like to see the stock information for: ")
print("1. NBK")
print("2. KHOT")
print("3. NAPESCO")
print("4. HCC")
print("5. ALKOUT")
print("0. Exit")
ch = input("Enter a number: ")
print()
while ch != '0':
if ch >= str(1) and ch <=str(5):
if int(ch) == 1:
source = requests.get('https://english.mubasher.info/markets/BK/stocks/NBK/profile')
elif int(ch)==2:
source = requests.get('https://english.mubasher.info/markets/BK/stocks/KHOT/profile')
elif int(ch)==3:
source = requests.get('https://english.mubasher.info/markets/BK/stocks/NAPESCO/profile')
elif int(ch)==4:
source = requests.get('https://english.mubasher.info/markets/BK/stocks/HCC/profile')
else:
source = requests.get('https://english.mubasher.info/markets/BK/stocks/ALKOUT/profile')
soup = BeautifulSoup(source.text, 'lxml')
info = soup.find('div', class_='market-summary__block')
for info in soup.find_all('div',class_='market-summary__block-row'):
item = info.find('span', class_='market-summary__block-text').text
item2 = info.find('span', class_='market-summary__block-number').text
print(item+": "+item2)
print()
else:
print("Invalid input.")
print("1. NBK")
print("2. KHOT")
print("3. NAPESCO")
print("4. HCC")
print("5. ALKOUT")
print("0. Exit")
print()
ch = input("Enter a number: ")
print()