Home  >  Q&A  >  body text

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...

大家讲道理大家讲道理2741 days ago589

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-18 10:33:36

    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

    reply
    0
  • Cancelreply