Beautiful Soup Question: Filtering Images based on their width and height attributes

P

PicURLPy

Hello,

I want to extract some image links from different html pages, in
particular i want extract those image tags which height values are
greater than 200. Is there an elegant way in BeautifulSoup to do this?
 
C

Chris Mellon

Hello,

I want to extract some image links from different html pages, in
particular i want extract those image tags which height values are
greater than 200. Is there an elegant way in BeautifulSoup to do this?

Most image tags "in the wild" don't have height attributes, you have
to download the image to see what size it is.
 
D

David Coffin

Hello,

I want to extract some image links from different html pages, in
particular i want extract those image tags which height values are
greater than 200. Is there an elegant way in BeautifulSoup to do this?

Yes.

soup.findAll(lambda tag: tag.name=="img" and tag.has_key("height")
and int(tag["height"]) > 200)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top