Some advice drop urllib and use Requests.
Here how that code would look with some advice,more here in tutorial part-1.
Here how that code would look with some advice,more here in tutorial part-1.
import requests from bs4 import BeautifulSoup url = "https://www.bbc.com/sport/football/46897172" response = requests.get(url) # lxml is faster parser soup = BeautifulSoup(response.content, 'lxml') # Now do not use dict call,easier to copy from page and just add one _ after class content = soup.find('div', class_="story-body sp-story-body gel-body-copy") with open('scraped_text.txt', 'w') as f_out: for p_tag in content.find_all('p'): print(p_tag.text) f_out.write(f'{p_tag.text}\n')