Thanks,
Christopher
result = tag.find('tag-name')
if result:
...
Or if you want to do error handling only when you haven't found anything:
if not result:
...
Or if you're feeling lazy:
assert result
Good luck,
Aaron DeVore
On Sun, Aug 8, 2010 at 3:51 AM, Christopher Brewster
<cbre...@gmail.com> wrote:
> How do I test in Beautifulsoup if there is a string attribute, and if there is not do some further processing, and if there is get the string?
> I am always falling over this AuttributeError.
>
> Thanks,
> Christopher
>
> --
> 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.
>
>
My current solution is a little unwieldy but works. I have a function 'extract_from_tag(tag)' which iterates over each item in tag.contents, performs various checks and tests if tag.contents > 0 in which cased recursively calls the function.
Messy but works. A hack in the old sense.
If there is a better way, I would appreciate suggestions.
Christopher
Also, any attribute access on Tag will succeed because an access that
isn't in __dict__ automatically does a find(name) search for a tag
with that name.
-Aaron DeVore