-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStockPriceInIndia.py
More file actions
41 lines (24 loc) · 954 Bytes
/
StockPriceInIndia.py
File metadata and controls
41 lines (24 loc) · 954 Bytes
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
import requests
from bs4 import BeautifulSoup
import re
import webbrowser
stock=input("Please enter name of the stock ")
page = requests.get("https://www.google.dz/search?q="+stock+"+share+price")
soup = BeautifulSoup(page.content,"lxml")
links = soup.findAll("a")
x=[]
for link in soup.find_all("a",href=re.compile("(?<=/url\\?q=)(htt.*://.*)")):
#print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
x.append(re.split(":(?=http)",link["href"].replace("/url?q=","")))
url=str(x[0])
unnes="[']'"
for char in unnes:
url=url.replace(char,'')
webbrowser.open(url)
res=requests.get(url)
icesoup = BeautifulSoup(res.text,features='html.parser')
price_box=icesoup.find('span',attrs={'class','txt15B nse_span_price_wrap hidden-xs'})
price=price_box.text
name_box=icesoup.find('h1',attrs={'class','pcstname'})
name=name_box.text
print("Price of the share "+name+" is "+price)