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!
CodePudding user response:
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']
CodePudding user response:
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'])