pythonweb-scrapingweb

Appending new elements into an empty list


Im facing issue with appending new elements into list. In first SS the data is shown which means it is present but when Im appending the data in a loop, the data shown is Nan. Please refer to the screen shots.

Data showing (screenshot)

result_items[0]['Media'][0]['Description']

Result NaN (screenshot)

for result in result_items:
    try:
            media_description.append(result[0]['Media'][0]['Description'])
    except:
            media_description.append(np.nan)   

media_description

Solution

  • In your 2nd image/cell of code, you are using result[0] whereas result itself is the element of the list, so there was no need to subscript the element.

    Replacing the line in 2nd cell with the following will fix the issue

    media_description.append(result['Media'][0]['Description'])