This is the code I currently have
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36'}
r = requests.get("http://www.google.com", headers=headers)
page_text = r.text
soup = BeautifulSoup(page_text, 'html.parser')
print(soup.prettify())
In theory it should send a request to google, get the text back and use beautifulsoup's method of prettify()
Here's their example code (from http://ift.tt/1Uiw4NI)
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc, 'html.parser')
print(soup.prettify())
Everytime I run this code I get the codec error. Here's a screenshot of the exact error
Aucun commentaire:
Enregistrer un commentaire