python3----练习......

1 # 上行遍历
2 soup = BeautifulSoup(demo, 'html.parser')
3 for parent in soup.a.parents:
4     if parent is None:
5         print(parent)
6     else:
7         print(parent.name)

 

posted @ 2018-01-27 15:15  jonm  阅读(170)  评论(0编辑  收藏  举报