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.
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.
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)