getting a KeyError:'href' any ideas?

LordLaraby Lord.Laraby at gmail.com
Sat Jan 7 01:08:55 EST 2006


You wrote:
> 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
Since you already found the anchor tag with the 'btn' class attribute,
just grab it's href attribute like so:
for incident in row('td', {'class':'all'}):
       n = incident.findNextSibling('a', {'class': 'btn'})
       link = n['href'] + "','"

Works for me...

LL




More information about the Python-list mailing list