3. 1子节点和子孙节点
soup.body.h1# 选中body 标签下的h1,这个h1 标签是body标签的子节点
同理,soup.div.find_all(‘img’)会找到所有div里面的img标签。
.children 和.descendants
对比代码如下:
html = urlopen('http://www.pythonscraping.com/pages/page3.html')
soup = BeautifulSoup(html, 'lxml')
children = soup.find('table',{
'id':'giftList'}).children
descendants = soup.find('table',{
'id':'giftList'}).descendants
sum =