Beautiful Soup [Python] and the extracting of text in a table

前端 未结 3 2078
不思量自难忘°
不思量自难忘° 2021-02-14 12:33

i am new to Python and to Beatiful Soup also! I heard about BS. It is told to be a great tool to parse and extract content. So here i am...:

I want to take the content

3条回答
  •  生来不讨喜
    2021-02-14 13:02

    Use "text" to get text between "td"

    1) First read table DOM using tag or ID

    soup = BeautifulSoup(self.driver.page_source, "html.parser")
    htnm_migration_table = soup.find("table", {'id':'htnm_migration_table'})
    

    2) Read tbody

    tbody = htnm_migration_table.find('tbody')
    

    3) Read all tr from tbody tag

    trs = tbody.find_all('tr')
    

    4) get all tds using tr

    for tr in trs:
          tds = tr.find_all('td')
          for td in tds:
          print(td.text)
    

提交回复
热议问题