Skip to content

Commit 930cba3

Browse files
committed
Fixed formatting, added missing import
1 parent b7271da commit 930cba3

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

chapter4/6-wikiHistories.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from urllib.request import urlopen
2+
from urllib.request import HTTPError
23
from bs4 import BeautifulSoup
34
import datetime
45
import json
@@ -9,8 +10,7 @@
910
def getLinks(articleUrl):
1011
html = urlopen("http://en.wikipedia.org"+articleUrl)
1112
bsObj = BeautifulSoup(html)
12-
return bsObj.find("div", {"id":"bodyContent"}).findAll("a",
13-
href=re.compile("^(/wiki/)((?!:).)*$"))
13+
return bsObj.find("div", {"id":"bodyContent"}).findAll("a", href=re.compile("^(/wiki/)((?!:).)*$"))
1414

1515
def getHistoryIPs(pageUrl):
1616
#Format of revision history pages is:
@@ -31,8 +31,7 @@ def getHistoryIPs(pageUrl):
3131

3232
def getCountry(ipAddress):
3333
try:
34-
response = urlopen("http://freegeoip.net/json/"
35-
+ipAddress).read().decode('utf-8')
34+
response = urlopen("http://freegeoip.net/json/"+ipAddress).read().decode('utf-8')
3635
except HTTPError:
3736
return None
3837
responseJson = json.loads(response)
@@ -51,4 +50,4 @@ def getCountry(ipAddress):
5150
print(historyIP+" is from "+country)
5251

5352
newLink = links[random.randint(0, len(links)-1)].attrs["href"]
54-
links = getLinks(newLink)
53+
links = getLinks(newLink)

0 commit comments

Comments
 (0)