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

前端 未结 3 2079
不思量自难忘°
不思量自难忘° 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:14

    I find Beautiful Soup very efficient tool so keep learning it :-) It is able to parse a page with invalid markup so it should be able to handle the page you refer. You may want to use command BeautifulSoup(html).prettify() command if you want to get a valid reformatted page source with valid markup.

    As for your question, the result of your first soup.findAll(...) command is also a Beautiful Soup object and you can make a second search in it, like this:

    table_soup = soup.findAll('table' ,attrs={'class':'bp_ergebnis_tab_info'})
    your_sample_text = table_soup.find("td").renderContents().strip()
    
    print your_sample_text
    

提交回复
热议问题