diff --git a/chapter1/2-beautifulSoup.py b/chapter1/2-beautifulSoup.py index 1911093..9b159fc 100644 --- a/chapter1/2-beautifulSoup.py +++ b/chapter1/2-beautifulSoup.py @@ -2,5 +2,5 @@ from bs4 import BeautifulSoup html = urlopen("http://www.pythonscraping.com/exercises/exercise1.html") -bsObj = BeautifulSoup(html.read()) +bsObj = BeautifulSoup(html.read(), "html.parser") print(bsObj.h1) diff --git a/chapter1/3-exceptionHandling.py b/chapter1/3-exceptionHandling.py index 331a7ee..a580526 100644 --- a/chapter1/3-exceptionHandling.py +++ b/chapter1/3-exceptionHandling.py @@ -1,8 +1,6 @@ from urllib.request import urlopen from urllib.error import HTTPError from bs4 import BeautifulSoup -import sys - def getTitle(url): try: @@ -11,7 +9,7 @@ def getTitle(url): print(e) return None try: - bsObj = BeautifulSoup(html.read()) + bsObj = BeautifulSoup(html.read(), "html.parser") title = bsObj.body.h1 except AttributeError as e: return None diff --git a/chapter5/3-scrapeCsv.py b/chapter5/3-scrapeCsv.py index 4b68abe..607dbf4 100644 --- a/chapter5/3-scrapeCsv.py +++ b/chapter5/3-scrapeCsv.py @@ -8,7 +8,7 @@ table = bsObj.findAll("table",{"class":"wikitable"})[0] rows = table.findAll("tr") -csvFile = open("files/editors.csv", 'wt', newline='', encoding='utf-8') +csvFile = open("../files/editors.csv", 'wt', newline='', encoding='utf-8') writer = csv.writer(csvFile) try: for row in rows: diff --git a/chapter5/8-sendEmailWhenChristmas.py b/chapter5/8-sendEmailWhenChristmas.py index d738ec3..3943ad0 100644 --- a/chapter5/8-sendEmailWhenChristmas.py +++ b/chapter5/8-sendEmailWhenChristmas.py @@ -10,9 +10,9 @@ def sendMail(subject, body): msg['From'] = "christmas_alerts@pythonscraping.com" msg['To'] = "ryan@pythonscraping.com" - s = smtplib.SMTP('localhost') - s.send_message(msg) - s.quit() + s = smtplib.SMTP('localhost') + s.send_message(msg) + s.quit() bsObj = BeautifulSoup(urlopen("https://isitchristmas.com/")) while(bsObj.find("a", {"id":"answer"}).attrs['title'] == "NO"):