Petrol Price Tracker in India ...
A simple Petrol price tracker in India using Python ..
The code ...
The website where we are going to scrape the in the information ..
Petrol Price Today (25 June 2021), Petrol Rate in India - Goodreturns
import requests pip install requests
import pandas as pd pip install pandas
from bs4 import BeautifulSoup pip install bs4
def getdata(url): # function to get the data
r = requests.get(url)
return r.text
htmldata = getdata("https://www.goodreturns.in/petrol-price.html") # the link
soup = BeautifulSoup(htmldata, 'html.parser') # initializing BeautifulSoup
mydatastr = ''
result = []
# formatting the data
for table in soup.find_all('tr'):
mydatastr += table.get_text()
mydatastr = mydatastr[1:]
itemlist = mydatastr.split("\n\n")
for item in itemlist[:-5]:
result.append(item.split("\n"))
df = pd.DataFrame(result[:-8])
print(df)
And the output ..
0 1 2
0 City Today Price Yesterday's Price
1 New Delhi ₹ 97.76 ₹ 97.76
2 Kolkata ₹ 97.63 ₹ 97.63
3 Mumbai ₹ 103.89 ₹ 103.89
4 Chennai ₹ 98.88 ₹ 98.88
5 Gurgaon ₹ 95.17 ₹ 95.22
6 Noida ₹ 95.34 ₹ 94.92
7 Bangalore ₹ 101.03 ₹ 101.03
8 Bhubaneswar ₹ 98.50 ₹ 98.85
9 Chandigarh ₹ 94.02 ₹ 94.02
10 Hyderabad ₹ 101.60 ₹ 101.60
11 Jaipur ₹ 105.18 ₹ 104.20
12 Lucknow ₹ 95.16 ₹ 94.95
13 Patna ₹ 99.80 ₹ 99.80
14 Trivandrum ₹ 99.50 ₹ 99.50
# on 25/06/2021
Comments
Post a Comment