Skip to content
Advertisement

Beautifulsoup/Writer returns an empty cell when exported to a CSV

I’m scraping a website to get the name, birth + death dates, and the name of the cemetery someone is buried in. For the most part, it is working quite well; however, when I exported the text to a CSV, I noticed that there’s a blank cell inserted in the name column after each page. I have a feeling this is probably related to the loop rather than an html tag, but I’m still learning. Any advice is welcome! Thanks everyone

Here’s an example of the problem in excel

JavaScript
JavaScript

I’ve tried to see if there were any similar tags happening at the beginning of each new page, but I couldn’t find anything that stood out.

Advertisement

Answer

Change

JavaScript

to

JavaScript

In simple terms:

since you haven’t defined how the new line should be it was adding rows

In technical terms:

The csv.writer module directly controls line endings and writes rn into the file directly. In Python 3 the file must be opened in untranslated text mode with the parameters ‘w’, newline=” (empty string) or it will write rrn on Windows, where the default text mode will translate each n into rn.

Hope this helps. Happy Coding :)

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement