Extract live gold price using web scrap – Data Science
in the following example we used three packages, they are
a) bs4 [Beautiful Soup for web scraping]
b) pandas [panel data for data representation ]
c) request [to get source / url]
#data science with Python - extracting Gold Price import bs4 import pandas as pd import requests url = 'https://www.goodreturns.in/gold-rates/bangalore.html' result = requests.get(url) soup = bs4.BeautifulSoup(result.content,'html.parser') price = soup.find_all('div', {"id":"current-price"}) for pr in price: print("Price:", pr.text) txt=pr.text from tkinter import * root=Tk() root.title('Gold Price') root.configure(bg='gold') root.geometry('200x100') w=Label(root, text=txt, bg='red', font='sans 14') b=Button(root, text="Close", fg='red', bg='yellow', command=root.destroy) w.pack() b.pack() root.mainloop()
Output of the above example is: