BeautifulSoup: How do I extract all the
  • s from a list of
      s that contains some nested
        s?
  • 后端 未结 3 582
    梦如初夏
    梦如初夏 2020-12-15 03:41

    My source code looks like:

    Header3 (Start here)

    • List items
    • Etc...
    3条回答
    •  谎友^
      谎友^ (楼主)
      2020-12-15 04:40

      import requests
      from bs4 import BeautifulSoup
      r = requests.get("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_list_test")
      soup =   BeautifulSoup(r.content,"lxml")
      w3schollsList = soup.find_all('body')
      for w3scholl in w3schollsList:
          ulList = w3scholl.find_all('li')
          for li in ulList:
              print(li)
      

      Note: here is to get the "li" inside the div we made

    提交回复
    热议问题