这二者的区别是一个列表,一个是迭代器
it=soup.body.contents
type(it)
Out[116]: list
所以对应children对象而言,可以使用next()函数
it=soup.body.children
next(it)
Out[106]: '\n'
next(it)
Out[107]: The Dormouse's story
next(it)
Out[108]: '\n'
next(it)
Out[109]:
Once upon a time there were three little sisters; and their names were
Elsie,
Lacie and
Tillie;
and they lived at the bottom of a well.
next(it)
Out[110]: '\n'
next(it)
Out[111]: ...
next(it)
Out[112]: '\n'