In this article we will see how we can get the current gold price in India. There is a variation in price of gold with time to time, price of gold is moved by a combination of supply, demand, and investor behavior. That seems simple enough, yet the way those factors work together is sometimes counterintuitive. Modules required and Installation: Requests : Requests allows you to send HTTP/1.1 requests extremely easily. There’s no need to manually add query strings to your URLs.
pip install requests
Beautiful Soup: Beautiful Soup is a library that makes it easy to scrape information from web pages. It sits atop an HTML or XML parser, providing Pythonic idioms for iterating, searching, and modifying the parse tree.
pip install beautifulsoup4
Explanation – We have the google search URL of the gold price from that we have scrape the price of the gold in Indian rupees and store it in a variable, which we further print it. Below is the implementation.
Python3
from bs4 import BeautifulSoup as BS
import requests
def get_price(url):
data = requests.get(url)
soup = BS(data.text, 'html.parser')
ans = soup.find("div", class_ = "BNeawe s3v9rd AP7Wnd").text
return ans
ans = get_price(url)
print(ans)
|
Output :
10g of 24k gold (99.9%): 42, 460 INR
Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.Dive into the future of technology - explore the
Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated :
24 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...