I learned to scrape data from website by this video:
I wonder why we could not see the dates as the content in the csv file and how to fix it. thanks a lot!
CodePudding user response:
I executed the code and noticed that you need to expand the cell length to see the date values.
One explanation is that date.text
has new line characters and empty spaces in it.
For example one of the date.text values is
'\n 2017/02/26\n '
You can clean this up by trimming all white space. Update your for loop with this:
for date, content in zip(dates, contents):
# trim white space fro date and content
clean_date = date.text.strip()
clean_content = content.text.strip()
print(clean_date "(" clean_content ")")
#WRITE EACH ITEM AS A NEW ROW IN THE CSV
writer.writerow([clean_date, clean_content])