getting a KeyError:'href' any ideas?

Mike Meyer mwm at mired.org
Thu Jan 5 20:25:54 CET 2006


"homepricemaps at gmail.com" <homepricemaps at gmail.com> writes:

Please use less whitespace in your posts in the future. There's really
no need to put two blank lines between sections.

> i have an
> href which looks like this:
> <td class="all">
>     <a class="btn" name="D1" href="http://www.cnn.com">
>         </a>
> here is my code
> for incident in row('td', {'class':'all'}):
>                 n = incident.findNextSibling('a', {'class': 'btn'})
>                 link = incident.findNextSibling['href'] + "','"
> any idea what i'm doing wrong here with the syntax?  thanks in advance

It's not the syntax, it's the logic. the a element is not a sibling of
the td element, it's a child. findNextSibling is going to return the
next td, assuming there is one. Trying to index
incident.findNextSibling in the next line is also broken. That's a
method, not an indexable object. So that line will also break.

        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list