-
Notifications
You must be signed in to change notification settings - Fork 0
/
top1000.py
executable file
·31 lines (29 loc) · 973 Bytes
/
top1000.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#Need to install wikipedia libary from: https://pypi.python.org/pypi/wikipedia
import wikipedia
import urllib.request, urllib.parse, urllib.error
import codecs
import ssl
#Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
startingPoint = wikipedia.page("Wikipedia:1,000 core topics")
startingPoint = startingPoint.links
count = 0
baseURL = "https://en.wikipedia.org/wiki/Special:Export/"
for item in startingPoint:
item = str(item)
print(item)
item = item.replace(" ", "_")
item = item.replace("/", "_")
url = baseURL + item
try:
data = urllib.request.urlopen(url, context=ctx)
#work around for articles with funky characters in there title
except:
continue
data = data.read().decode()
name = item + ".xml"
fileHandle = codecs.open(name, 'w', "utf-8")
fileHandle.write(data)
fileHandle.close()