Jan-15-2019, 08:03 PM
Hi,
The following code is meant to get table for "IFPI 2014 data" and put it in a csv file.
Although the csv file is being created but there is no data in it.
Thanks
The following code is meant to get table for "IFPI 2014 data" and put it in a csv file.
Although the csv file is being created but there is no data in it.
import csv import urllib.request from bs4 import BeautifulSoup f = open('dataoutput.csv', 'w', newline = '') writer = csv.writer(f) soup = BeautifulSoup(urllib.request.urlopen("https://en.wikipedia.org/wiki/Global_music_industry_market_share_data").read(), 'lxml') tbody = soup('table', {"class":"wikitable plainrowheaders sortable"})[0].find_all('tr') for row in tbody: cols = row.findChildren(recursive=False) cols = [ele.text.script() for ele in cols] writer.writerow(cols) print(cols)I keep getting this error message
Traceback (most recent call last): File "C:\Users\Hass\eclipse-workspace\FTS\src\Webscraping.py", line 18, in <module> cols = [ele.text.script() for ele in cols] File "C:\Users\Hass\eclipse-workspace\FTS\src\Webscraping.py", line 18, in <listcomp> cols = [ele.text.script() for ele in cols] AttributeError: 'str' object has no attribute 'script'Can someone please point out where I am going wrong and how to fix it.
Thanks