# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
import requests
from bs4 import BeautifulSoup
import csv

month_list =['january','february','march','april','may','june','july','august','september','october','november','december']
year ='2012'
for month in month_list:

    page = requests.get('https://www.goldpriceindia.com/gold-price-' + month + '-'+year+'.php')
    soup = BeautifulSoup(page.text, 'html.parser')


    h4_title = soup.find_all('h4')

    list_h4 =[]
    for i in h4_title :
        value = i.text
        list_h4.append(value)

    print(list_h4)

    table_data = soup.find_all(class_= 'table-data dayyeartable')


    with open('dataset'+year+'.csv','a') as csvfile:
        csvwriter = csv.writer(csvfile , delimiter =',', quoting=csv.QUOTE_MINIMAL )
        count =0
        for td in table_data:

            th = td.find_all('th')
        
            l =[]
            tds = td.find_all('td')
            m =[]
            for i in tds:
                value = i.text
                m.append(value.encode('ascii', 'ignore').decode('ascii'))
            if(len(m)==4):
                continue
            for i in th:
                l.append(i.text)

            date = str(list_h4[count])[14:]
            day = date[:2]
            year = date[-4:]
            dicti = {'january':'01','february':'02','march':'03','april':'04','may':'05','june':'06','july':'07','august':'08','september':'09'
            ,'october':'10','november':'11','december':'12'}
            for key,value in dicti.items():
                if(key == month):
                    month_value = value
            p=int(m[1].replace(",",""))
            csvwriter.writerow([day+'-'+month_value+'-'+year, p])
            print(m)
            count = count +1
# -



StarcoderdataJupyterScriptsDedupFiltered