How to print out the first and last 1000 lines using beautiful soup
<p>I am trying to print out the first and last 1000 lines using "prettify' from BeautifulSoup.  I have downloaded Kafka's The Metamorphosis to my hard drive and I've successfully created a BeautifulSoup object:</p>

<p>Due to captcha issues with the Gutenberg site, I saved a copy of the document on my hard drive.</p>

<pre><code>page = open('meta.htm', 'r').read()
soup = BeautifulSoup(page, "lxml")
</code></pre>

<p>How do I use <code>soup.prettify()</code> to print out the first and last 1000 lines of the document?</p>

<p>Just <em>slice</em> them:</p>

<pre><code>result = soup.prettify().splitlines()
print('\n'.join(result[:1000] + result[-1000:]))
</code></pre>

python beautifulsoup prettify