I am scraping out the ‘h2’ and ‘h3’ tags from some html pages and want to write them to a csv file under particular columns. How to create columns and then insert rows under them using python scrapy.
My code is:
def parse(self, response):
hxs = HtmlXPathSelector(response)
sites = hxs.select('//ul/li')
f = open("fquestdata.csv","wb")
for site in sites:
quest = site.select('//h2').extract()
ans = site.select('//h3').extract()
f.write(ans)
but it gives an error that says:
exceptions.TypeError: must be string or buffer, not list
You are getting more then one answer. Try
Cheers!