1

I've tried the following:

import urllib

link = 'https://automatetheboringstuff.com/chapter7/'
f = urllib.request.urlopen(link)
myfile = f.read()
print(myfile)

But that just seems to return the page's source rather than the text content.

Fashinated
  • 55
  • 1
  • 8

1 Answers1

1

If you only want to get chapter text, beautiful soup is your choice, I think.

In your case:

import requests
from bs4 import BeautifulSoup

res = requests.get('https://automatetheboringstuff.com/chapter7/')
soup = BeautifulSoup(res.text, 'html.parser')
print(soup.find('div', { "class" : "book" }).text)
shomel
  • 196
  • 1
  • 10