Using BeautifulSoup to grab all the HTML between two tags

前端 未结 4 1357
情深已故
情深已故 2020-12-25 12:57

I have some HTML that looks like this:

Title

//a random amount of p/uls or tagless text

Next Title

4条回答
  •  时光说笑
    2020-12-25 13:44

    This is the clear BeautifulSoup way, when the second h1 tag is a sibling of the first:

    html = u""
    for tag in soup.find("h1").next_siblings:
        if tag.name == "h1":
            break
        else:
            html += unicode(tag)
    

提交回复
热议问题