[Tutor] BeautifulSoup - getting cells without new line characters
jonasmg at softhome.net
jonasmg at softhome.net
Sat Apr 1 23:51:36 CEST 2006
Danny Yoo writes:
>
>
>> > Have you read a Python tutorial? It seems like some of the things you
>> > are struggling with might be addressed in general Python material.
>>
>>
>> You consider a thing about me. If I ask something it is because I cannot
>> find the solution. I do not it by whim.
>
> Hello Jonas,
>
> Yes, but don't take Kent's question as a personal insult --- he's asking
> because it looks like you're having trouble interpreting error messages or
> considering border cases.
>
Sorry Kent if my answer was very rude. I very was tired to try many things
without no good result.
> Anyway, the program snippet above makes assumptions, so let's get those
> out of the way. Concretely:
>
> for rows in table('tr'):
> print rows('td')[0]
>
> makes an assumption that is not necessarely true:
>
> * It assumes that each row has a td element.
>
> Do you understand the border case here? In particular:
>
> * What if you hit a TR table row that does not have any TD columns?
>
Danny, you give me the idea. The problem is that the first row has TH
columns (not TD). So:
for row in table('tr'):
if row('td'):
print row('td')[0].string
More information about the Tutor
mailing list