Getting attribute name rather than value with BS4

Viewed 84

I have managed to pull out most of the various attributes of a site I am scraping, but have come short trying to extract the value of something within the div declarator itself.

Specifically, assuming the following:

<div class="item" data-color="red" data-itemid="abc">Red Slippers</div>

I am after the value inside data-itemid > abc.

I cannot seem to get something that isn't looking at the value inside the div: i.e. Red Slippers, which is not what I am after.

I have tried the following, without luck:

item_id = soup.find('data-itemid')

Any ideas?

1 Answers
Related