Skip to content
Advertisement

Converting elements list into single dictionary while scraping

I am scraping Glassdoor companies. There is a benefits section which will be different for every company, so I am grabbing all the elements in the div. That returns a list. Is there anyway to convert these into key:value pairs while scraping. They need to be written to a csv inside a loop.

JavaScript

enter image description here

As of now, I am writing the list in 1 column like so.

JavaScript

Ideally it should be like this.

JavaScript

I have tried but cannot think of a way to do this because characters are returned one at a time, so cannot find a way to make the headline text key and the value of it as value and I cannot come up with a way to create a dict out of this. Any help is much appreciated.

Advertisement

Answer

you can use the string find method to find the brackets and extract the value to save it into a dictionary

JavaScript

Output is :

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