Hey I've been trying to extract a timestamp from a html page and I've tried looking at other methods but I can't seem to apply to my case. I'm trying to receive the timestamp for many messages but I can't get the data from the div.
<div data-sigil="message-text" data-store='{"timestamp":1425541012960,"author":100004932254581,"uuid":"mid.1425541012942:e2ebd68467f39a6954"}' data-store-id="53666">
<span>
I'm a antibacterial
</span>
<div class="messageAttachments">
</div>
</div>
The code I'm using is this.
timestamp = []
soup = BeautifulSoup(open('Messenger.html', encoding='utf-8'), 'html.parser')
div = soup.div
timestamp.append = div.attrs['data-store']
print(timestamp)
There are a number of timestamps I'm trying to list as well if that helps.
edit: here is the error message I'm receiving.
timestamp.append = div.attrs['data-store']
KeyError: 'data-store'
edit2: using a combination of both answers below I got it working thanks to everyone that helped :)
time = soup.find_all('div', {'data-sigil':'message-text'})
#print(len(time))
for i in range(len(time)):
stamp = ast.literal_eval(time[i].attrs['data-store'])['timestamp']
timestamp.append(stamp)
#print(timestamp[i])