<code>import requests
import pandas as pd
from bs4 import BeautifulSoup as bs
from io import StringIO
url = "https://www.tickertape.in/stocks/oil-and-natural-gas-corporation-ONGC"
r = requests.get(url=url)#,headers=headers)
soup = bs(r.content,'html5lib')
fin = soup.find_all(class_="financials-table-root")
for f in fin:
str_data = f.text
break
print(str_data)
df = pd.read_csv(StringIO(str_data))
print(df)
</code>
<code>import requests
import pandas as pd
from bs4 import BeautifulSoup as bs
from io import StringIO
url = "https://www.tickertape.in/stocks/oil-and-natural-gas-corporation-ONGC"
r = requests.get(url=url)#,headers=headers)
soup = bs(r.content,'html5lib')
fin = soup.find_all(class_="financials-table-root")
for f in fin:
str_data = f.text
break
print(str_data)
df = pd.read_csv(StringIO(str_data))
print(df)
</code>
import requests
import pandas as pd
from bs4 import BeautifulSoup as bs
from io import StringIO
url = "https://www.tickertape.in/stocks/oil-and-natural-gas-corporation-ONGC"
r = requests.get(url=url)#,headers=headers)
soup = bs(r.content,'html5lib')
fin = soup.find_all(class_="financials-table-root")
for f in fin:
str_data = f.text
break
print(str_data)
df = pd.read_csv(StringIO(str_data))
print(df)
This is not giving me the desired result. I am not good with handing strings, please guide me a way to extract the values from the str_data, so that I can use it for further calculations.
Output of str_data:
<code>Financial YearFY 2016FY 2017FY 2018FY 2019FY 2020FY 2021FY 2022FY 2023FY 2024TTMTotal Revenue1,33,084.682,95,230.293,33,135.154,32,783.974,06,772.743,15,162.695,00,202.156,41,531.266,57,654.976,57,751.89Raw Materials36,666.931,75,376.732,02,298.512,75,523.612,69,975.372,05,913.122,25,616.932,66,120.045,41,837.995,42,659.83Power & Fuel Cost1,182.381,957.932,177.502,139.732,078.921,980.442,239.162,174.44Employee Cost9,230.1715,128.1614,970.7215,850.5015,531.2614,135.1215,235.7414,898.79Selling & Administrative Expenses35,735.3136,378.9034,331.5839,621.4429,357.6623,004.0836,347.6144,365.47Operating & Other expenses10,068.00860.7212,038.3915,262.6036,742.869,385.991,34,092.392,38,475.37EBITDA40,201.8965,527.8567,318.4584,386.0953,086.6760,743.9486,670.3275,497.151,15,816.981,15,092.06Depreciation/Amortization16,384.0620,219.2023,111.9123,703.7026,634.8825,538.4726,883.1624,557.0628,762.7428,750.79PBIT23,817.8345,308.6544,206.5460,682.3926,451.7935,205.4759,787.1650,940.0987,054.2486,341.27Interest & Other Items3,765.583,591.114,999.045,836.737,489.345,079.035,696.047,889.3610,194.1710,194.17PBT20,052.2541,717.5439,207.5054,845.6618,962.4530,126.4454,091.1243,050.7376,860.0776,147.10Taxes & Other Items7,177.0417,298.2917,101.5824,299.628,158.8513,822.058,568.997,610.2827,638.6927,459.24Net Income12,875.2124,419.2522,105.9230,546.0410,803.6016,304.3945,522.1335,440.4549,221.3848,687.86EPS10.0319.0317.2324.048.5912.9636.1928.1739.1338.70DPS5.677.556.607.005.003.6010.5011.2512.2510.25Payout ratio0.560.400.380.290.580.280.290.400.310.26
</code>
<code>Financial YearFY 2016FY 2017FY 2018FY 2019FY 2020FY 2021FY 2022FY 2023FY 2024TTMTotal Revenue1,33,084.682,95,230.293,33,135.154,32,783.974,06,772.743,15,162.695,00,202.156,41,531.266,57,654.976,57,751.89Raw Materials36,666.931,75,376.732,02,298.512,75,523.612,69,975.372,05,913.122,25,616.932,66,120.045,41,837.995,42,659.83Power & Fuel Cost1,182.381,957.932,177.502,139.732,078.921,980.442,239.162,174.44Employee Cost9,230.1715,128.1614,970.7215,850.5015,531.2614,135.1215,235.7414,898.79Selling & Administrative Expenses35,735.3136,378.9034,331.5839,621.4429,357.6623,004.0836,347.6144,365.47Operating & Other expenses10,068.00860.7212,038.3915,262.6036,742.869,385.991,34,092.392,38,475.37EBITDA40,201.8965,527.8567,318.4584,386.0953,086.6760,743.9486,670.3275,497.151,15,816.981,15,092.06Depreciation/Amortization16,384.0620,219.2023,111.9123,703.7026,634.8825,538.4726,883.1624,557.0628,762.7428,750.79PBIT23,817.8345,308.6544,206.5460,682.3926,451.7935,205.4759,787.1650,940.0987,054.2486,341.27Interest & Other Items3,765.583,591.114,999.045,836.737,489.345,079.035,696.047,889.3610,194.1710,194.17PBT20,052.2541,717.5439,207.5054,845.6618,962.4530,126.4454,091.1243,050.7376,860.0776,147.10Taxes & Other Items7,177.0417,298.2917,101.5824,299.628,158.8513,822.058,568.997,610.2827,638.6927,459.24Net Income12,875.2124,419.2522,105.9230,546.0410,803.6016,304.3945,522.1335,440.4549,221.3848,687.86EPS10.0319.0317.2324.048.5912.9636.1928.1739.1338.70DPS5.677.556.607.005.003.6010.5011.2512.2510.25Payout ratio0.560.400.380.290.580.280.290.400.310.26
</code>
Financial YearFY 2016FY 2017FY 2018FY 2019FY 2020FY 2021FY 2022FY 2023FY 2024TTMTotal Revenue1,33,084.682,95,230.293,33,135.154,32,783.974,06,772.743,15,162.695,00,202.156,41,531.266,57,654.976,57,751.89Raw Materials36,666.931,75,376.732,02,298.512,75,523.612,69,975.372,05,913.122,25,616.932,66,120.045,41,837.995,42,659.83Power & Fuel Cost1,182.381,957.932,177.502,139.732,078.921,980.442,239.162,174.44Employee Cost9,230.1715,128.1614,970.7215,850.5015,531.2614,135.1215,235.7414,898.79Selling & Administrative Expenses35,735.3136,378.9034,331.5839,621.4429,357.6623,004.0836,347.6144,365.47Operating & Other expenses10,068.00860.7212,038.3915,262.6036,742.869,385.991,34,092.392,38,475.37EBITDA40,201.8965,527.8567,318.4584,386.0953,086.6760,743.9486,670.3275,497.151,15,816.981,15,092.06Depreciation/Amortization16,384.0620,219.2023,111.9123,703.7026,634.8825,538.4726,883.1624,557.0628,762.7428,750.79PBIT23,817.8345,308.6544,206.5460,682.3926,451.7935,205.4759,787.1650,940.0987,054.2486,341.27Interest & Other Items3,765.583,591.114,999.045,836.737,489.345,079.035,696.047,889.3610,194.1710,194.17PBT20,052.2541,717.5439,207.5054,845.6618,962.4530,126.4454,091.1243,050.7376,860.0776,147.10Taxes & Other Items7,177.0417,298.2917,101.5824,299.628,158.8513,822.058,568.997,610.2827,638.6927,459.24Net Income12,875.2124,419.2522,105.9230,546.0410,803.6016,304.3945,522.1335,440.4549,221.3848,687.86EPS10.0319.0317.2324.048.5912.9636.1928.1739.1338.70DPS5.677.556.607.005.003.6010.5011.2512.2510.25Payout ratio0.560.400.380.290.580.280.290.400.310.26
Output of print(df):
<code>Empty DataFrame
Columns: [Financial YearFY 2016FY 2017FY 2018FY 2019FY 2020FY 2021FY 2022FY 2023FY 2024TTMTotal Revenue1, 33, 084.682, 95, 230.293, 33.1, 135.154, 32, 783.974, 06, 772.743, 15, 162.695, 00, 202.156, 41, 531.266, 57, 654.976, 57.1, 751.89Raw Materials36, 666.931, 75, 376.732, 02, 298.512, 75.1, 523.612, 69, 975.372, 05, 913.122, 25, 616.932, 66, 120.045, 41.1, 837.995, 42, 659.83Power & Fuel Cost1, 182.381, 957.932, 177.502, 139.732, 078.921, 980.442, 239.162, 174.44Employee Cost9, 230.1715, 128.1614, 970.7215, 850.5015, 531.2614, 135.1215, 235.7414, 898.79Selling & Administrative Expenses35, 735.3136, 378.9034, 331.5839, 621.4429, 357.6623, 004.0836, 347.6144, 365.47Operating & Other expenses10, 068.00860.7212, 038.3915, 262.6036, 742.869, 385.991, 34, 092.392, 38, 475.37EBITDA40, 201.8965, 527.8567, 318.4584, 386.0953, 086.6760, 743.9486, 670.3275, 497.151, 15.1, 816.981, 15.2, 092.06Depreciation/Amortization16, 384.0620, 219.2023, 111.9123, 703.7026, 634.8825, 538.4726, 883.1624, 557.0628, 762.7428, 750.79PBIT23, 817.8345, 308.6544, 206.5460, 682.3926, 451.7935, ...]
Index: []
</code>
<code>Empty DataFrame
Columns: [Financial YearFY 2016FY 2017FY 2018FY 2019FY 2020FY 2021FY 2022FY 2023FY 2024TTMTotal Revenue1, 33, 084.682, 95, 230.293, 33.1, 135.154, 32, 783.974, 06, 772.743, 15, 162.695, 00, 202.156, 41, 531.266, 57, 654.976, 57.1, 751.89Raw Materials36, 666.931, 75, 376.732, 02, 298.512, 75.1, 523.612, 69, 975.372, 05, 913.122, 25, 616.932, 66, 120.045, 41.1, 837.995, 42, 659.83Power & Fuel Cost1, 182.381, 957.932, 177.502, 139.732, 078.921, 980.442, 239.162, 174.44Employee Cost9, 230.1715, 128.1614, 970.7215, 850.5015, 531.2614, 135.1215, 235.7414, 898.79Selling & Administrative Expenses35, 735.3136, 378.9034, 331.5839, 621.4429, 357.6623, 004.0836, 347.6144, 365.47Operating & Other expenses10, 068.00860.7212, 038.3915, 262.6036, 742.869, 385.991, 34, 092.392, 38, 475.37EBITDA40, 201.8965, 527.8567, 318.4584, 386.0953, 086.6760, 743.9486, 670.3275, 497.151, 15.1, 816.981, 15.2, 092.06Depreciation/Amortization16, 384.0620, 219.2023, 111.9123, 703.7026, 634.8825, 538.4726, 883.1624, 557.0628, 762.7428, 750.79PBIT23, 817.8345, 308.6544, 206.5460, 682.3926, 451.7935, ...]
Index: []
</code>
Empty DataFrame
Columns: [Financial YearFY 2016FY 2017FY 2018FY 2019FY 2020FY 2021FY 2022FY 2023FY 2024TTMTotal Revenue1, 33, 084.682, 95, 230.293, 33.1, 135.154, 32, 783.974, 06, 772.743, 15, 162.695, 00, 202.156, 41, 531.266, 57, 654.976, 57.1, 751.89Raw Materials36, 666.931, 75, 376.732, 02, 298.512, 75.1, 523.612, 69, 975.372, 05, 913.122, 25, 616.932, 66, 120.045, 41.1, 837.995, 42, 659.83Power & Fuel Cost1, 182.381, 957.932, 177.502, 139.732, 078.921, 980.442, 239.162, 174.44Employee Cost9, 230.1715, 128.1614, 970.7215, 850.5015, 531.2614, 135.1215, 235.7414, 898.79Selling & Administrative Expenses35, 735.3136, 378.9034, 331.5839, 621.4429, 357.6623, 004.0836, 347.6144, 365.47Operating & Other expenses10, 068.00860.7212, 038.3915, 262.6036, 742.869, 385.991, 34, 092.392, 38, 475.37EBITDA40, 201.8965, 527.8567, 318.4584, 386.0953, 086.6760, 743.9486, 670.3275, 497.151, 15.1, 816.981, 15.2, 092.06Depreciation/Amortization16, 384.0620, 219.2023, 111.9123, 703.7026, 634.8825, 538.4726, 883.1624, 557.0628, 762.7428, 750.79PBIT23, 817.8345, 308.6544, 206.5460, 682.3926, 451.7935, ...]
Index: []
Trying to make a dataframe to use the values.