How to look for style="display: none" ??

1,451 views
Skip to first unread message

-e

unread,
Feb 16, 2011, 7:08:03 PM2/16/11
to beautifulsoup
I've got all the rows of a table and am going through them one by one
(doing some processing) but I want to skip the ones that are not
displayed (style: display:none;). I know this has got to be easy but
I can find it. My rows look like:

<tr><td>e1</td><td>e1</td>
<tr style="display: none;"><td>e1</td><td>e1</td>

One catch is some rows don't have a style.

Please, any thoughts?

-e

unread,
Feb 17, 2011, 8:51:54 AM2/17/11
to beautifulsoup
The solution I came up with is to get all of the rows that are hidden
before my loop
(rowsToSkip=soup.findAll('tr',style=re.compile('display: name')) and
then check to see if each row is in that set (if thisRow in rowToSkip
continue).

kinda ugly, but works. any better ideas?

Aaron DeVore

unread,
Feb 17, 2011, 1:16:41 PM2/17/11
to beauti...@googlegroups.com
This is a little hackish too, but...

[tag for tag in soup.findAll("tr")
if "display: none" not in tag.get("style", "")]

-Aaron DeVore

> --
> You received this message because you are subscribed to the Google Groups "beautifulsoup" group.
> To post to this group, send email to beauti...@googlegroups.com.
> To unsubscribe from this group, send email to beautifulsou...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/beautifulsoup?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages