I want to write to csv file in scrapy
for rss in rsslinks:
item = AppleItem()
item['reference_link'] = response.url
base_url = get_base_url(response)
item['rss_link'] = urljoin_rfc(base_url,rss)
#item['rss_link'] = rss
items.append(item)
#items.append("\n")
f = open(filename,'a+') #filename is apple.com.csv
for item in items:
f.write("%s\n" % item)
My output is this:
{'reference_link': 'http://www.apple.com/'
'rss_link': 'http://www.apple.com/rss '
{'reference_link': 'http://www.apple.com/rss/'
'rss_link': 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/newreleases/limit=10/rss.xml'}
{'reference_link': 'http://www.apple.com/rss/'
'rss_link': 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/newreleases/limit=25/rss.xml'}
What I want is this format:
reference_link rss_link
http://www.apple.com/ http://www.apple.com/rss/
Try tablib.
You need to
You could approach it like:
Note that
"{}\n".format(s)
gives the same result as"%s\n" % s
.This is what worked for me using Python3:
simply crawl with
-o csv
, like:Best approach to solve this problem is to use python in-build csv package.