python - 标签树的下行遍历如何跳过第一个标签
本文介绍了python - 标签树的下行遍历如何跳过第一个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
爬取网页用下行遍历的找出了我要的标签,但第一个的内容我是不要的用.children好像无法跳出第一个标签
for tr in soup.find(id="endText").children:
if tr.string is not None:
a = tr.string
网页的内容:
原链接:http://digi.163.com/14/1115/0...
解决方案
p_list = list(soup.find(id="endText").find_all('p'))
for p in p_list[1:]:
text = p.get_text()
img = p.find("img")
if img:
print img.get('src')
if text:
print text
这篇关于python - 标签树的下行遍历如何跳过第一个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文