Moronis2234
Moronis2234

Reputation: 67

web scrapping, is there a reason why src doesn't work when I try to get the contents within src

Kanye West Wikipedia Webscrape First image

The html from the Kanye wiki for the first image

I'm confused on why it isn't working. I feel like it can't be because src doesn't exist, because it does...? My apologies if this is an obvious fix, I'm fairly new to coding, and just started learning web scraping today. If anyone has any good resources to learn better, please lmk!

Upvotes: 0

Views: 101

Answers (2)

Captain Caveman
Captain Caveman

Reputation: 1546

Please post your source code next time. This code will extract all image src values.

find_all_images = bs.find_all('img')
for image in images:
    if image.has_attr('src'):
        print(img['src'])

Upvotes: 1

AdamMcKay
AdamMcKay

Reputation: 570

Your comp variable is a Tag object. You'll need to look at it's contents and retrieve the attributes you want that way.

print(comp.contents[0].attrs['src']

Upvotes: 0

Related Questions