Skip to content

Commit 1f93fba

Browse files
Ryan MitchellRyan Mitchell
authored andcommitted
2 parents 88f9755 + 75c4c71 commit 1f93fba

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

chapter5/2-createCsv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import csv
22
#from os import open
33

4-
csvFile = open("../files/test.csv", 'w+')
4+
csvFile = open("../files/test.csv", 'w+', newline='')
55
try:
66
writer = csv.writer(csvFile)
77
writer.writerow(('number', 'number plus 2', 'number times 2'))
88
for i in range(10):
99
writer.writerow( (i, i+2, i*2))
1010
finally:
11-
csvFile.close()
11+
csvFile.close()

chapter5/3-scrapeCsv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
table = bsObj.findAll("table",{"class":"wikitable"})[0]
99
rows = table.findAll("tr")
1010

11-
csvFile = open("files/editors.csv", 'wt')
11+
csvFile = open("files/editors.csv", 'wt', newline='', encoding='utf-8')
1212
writer = csv.writer(csvFile)
1313
try:
1414
for row in rows:
1515
csvRow = []
1616
for cell in row.findAll(['td', 'th']):
1717
csvRow.append(cell.get_text())
18-
writer.writerow(csvRow)
18+
writer.writerow(csvRow)
1919
finally:
2020
csvFile.close()

chapter5/5-storeWikiLinks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from urllib.request import urlopen
22
from bs4 import BeautifulSoup
3+
import re
34
import datetime
45
import random
56
import pymysql
@@ -30,4 +31,4 @@ def getLinks(articleUrl):
3031
links = getLinks(newArticle)
3132
finally:
3233
cur.close()
33-
conn.close()
34+
conn.close()

0 commit comments

Comments
 (0)