Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

13
  • 3
    How if we want to select some line, just said, line #3? Commented Aug 26, 2014 at 19:19
  • 7
    After going through a lot of stackoverflow answers, I feel like this is the best option for me. One problem I encountered is that lines were added together in some cases. I was able to overcome it by adding a separator in get_text function: text = soup.get_text(separator=' ') Commented Sep 2, 2015 at 9:54
  • 8
    Instead of soup.get_text() I used soup.body.get_text(), so that I don't get any text from the <head> element, such as the title. Commented Jan 15, 2016 at 13:50
  • 11
    For Python 3, from urllib.request import urlopen Commented May 19, 2017 at 7:48
  • 3
    Actually you can achieve the same clean result without these manual loops just using two additional standard parameters: soup.get_text(separator='\n', strip=True) Commented Jun 16, 2020 at 12:42