I am having a problem while storing the data into a CSV file it is not storing properly.
import urllib2
import csv
from bs4 import BeautifulSoup
url='http://contentlinks.dionglobal.in/ib/closeprices.asp?Exchange=NSE&Startname=A'
page = urllib2.urlopen(url)
soup = BeautifulSoup(page, 'html.parser')
for name_box in soup.find_all('tr', class_='alternate'):
name = name_box.text.strip()
print(name)
with open('Book1.csv', 'a') as csv_file:
writer = csv.writer(csv_file)
writer.writerow([name])
for namebox2 in soup.find_all('tr', class_='alternate1'):
name3 = namebox2.text.strip()
with open('Book1.csv', 'a') as csv_file:
writer = csv.writer(csv_file)
writer.writerow([name3])
print(type(name3))
pandas.read_html(). It may solve all at once.