Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Henrik Christensen
Python Web Development Techdegree Student 38,322 Pointscsv to excel problem
Hi,
I'm trying to scrape a single page for data for practice, but I'm having a problem with my .csv file - when I open it in excel all the data is displayed in a single column :-/
Any1 know how to fix this?
import csv
import scrapy
class CommunitySpider(scrapy.Spider):
name = 'community'
start_urls = ['https://teamtreehouse.com/community']
def parse(self, response):
with open('community.csv', 'a', newline='') as csvfile:
writer = csv.writer(csvfile, dialect='excel')
writer.writerow(['topic', 'has_been_answered'])
for question in response.css('li.discussion-item'):
topic = question.css('ul.discussion-tags li.discussion-tag a::text').extract_first()
has_been_answered = 0
if question.css('p.discussion-answer-info span svg.checkmark-icon'):
has_been_answered = 1
writer.writerow([topic, str(has_been_answered)])