def save_page(countBegin, countEnd, way):
# count = int(page_count())
masUrl = []
for a in range(countBegin, countEnd, way):
url = 'http://www.epicwar.com/maps/?page=' + str(a) + '&sort=time&order=desc'
masUrl.append(url)
f = open(path + fileName, 'wb')
f.close()
f = open(path + fileName, 'a')
for a in masUrl:
request = urllib.request.urlopen(a)
temp = open(path + 'temp', 'wb')
temp.write(request.read())
string = open(path + 'temp').read()
pattern = re.compile(r'<a.+?\s*</td>\s+<td\s.+?</td>')
found = re.findall(pattern, string)
for b in found:
f.write(b)
print(a)
if UnicodeError:
continue
f.close()
<...>
def mProc():
from multiprocessing import Process
count = int(page_count())
p1 = Process(target=save_page, args=(round(count / 5), 0, -1))
p1.start()
p2 = Process(target=save_page, args=(round(count / 5 * 2), round(count / 5), -1))
p2.start()
p3 = ...
if __name__ == '__main__':
mProc()
вроде бы добавил обработку ошибок, но все равно выдает
Process Process-1:
Traceback (most recent call last):
File “C:\Python340\lib\multiprocessing\process.py”, line 254, in _bootstrap
self.run()
File “C:\Python340\lib\multiprocessing\process.py”, line 93, in run
self._target(*self._args, **self._kwargs)
File “C:\Users\abaga\PycharmProjects\learn\ew.py”, line 48, in save_page
string = open(path + ‘temp’).read()
File “C:\Python340\lib\encodings\cp1251.py”, line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)
UnicodeDecodeError: ‘charmap’ codec can't decode byte 0x98 in position 5221: character maps to <undefined>