Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chapter1/2-beautifulSoup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 1 addition & 3 deletions chapter1/3-exceptionHandling.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from urllib.request import urlopen
from urllib.error import HTTPError
from bs4 import BeautifulSoup
import sys


def getTitle(url):
try:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chapter5/3-scrapeCsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions chapter5/8-sendEmailWhenChristmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down