11from  urllib .request  import  urlopen 
2+ from  urllib .request  import  HTTPError 
23from  bs4  import  BeautifulSoup 
34import  datetime 
45import  json 
910def  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
1515def  getHistoryIPs (pageUrl ):
1616    #Format of revision history pages is:  
@@ -31,8 +31,7 @@ def getHistoryIPs(pageUrl):
3131
3232def  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