I need to extract csv file from html page see below and once I get that I can do stuff with it. below is code to extract that particular line of html code from a previous assignment. The url is 'https://vincentarelbundock.github.io/Rdatasets/datasets.html' that is test code so it breaks temporarly when it finds that line. part of the line with my csv is href is csv/datasets/co2.csv ( unicode I think as type)
how to open the co2.csv? sorry about any formatting issues with the question. The code has been sliced and diced by the editor.
import urllib
url = 'https://vincentarelbundock.github.io/Rdatasets/datasets.html'
from BeautifulSoup import *
def scrapper(url,k):
c=0
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
#. Retrieve all of the anchor tags
tags = soup('a')
for tag in tags:
y= (tag.get('href', None))
#print ((y))
if y == 'csv/datasets/co2.csv':
print y
break
c= c+ 1
if c is k:
return y
print(type(y))
for w in range(29):
print(scrapper(url,w))
co2.csvfile, or if you want to process all csv files that are linked on the html page.