def get_cookie(url):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36',
'Cookie':'_ga=GA1.2.1727590418.1586931917; Hm_lvt_020fbaad6104bcddd1db12d6b78812f6=1586931917,1586933356; _gid=GA1.2.779081895.1587085857; _gat_gtag_UA_75859356_3=1; footprints=eyJpdiI6IjJHd29JdkdXbERJbWhkdUlpTzFWQ2c9PSIsInZhbHVlIjoiWmRWY3V4XC9kY3pDVWVqakJOZFhRR21HV295ejdsVlB4M2VMdjZsMFFrc3R4UHN1ZXFYaE96cHFYenhxSE5WVlIiLCJtYWMiOiI4N2M0MDFmMDllYjhmMmY5MDQ2MGE4NTI3Y2ZjMDQ5NmMyNmM4MDZkMWUxYWI0MWM0YTIxZTZhZDI3NzViNjI3In0%3D; XSRF-TOKEN=eyJpdiI6Im5VMWVCSTBMc1p5YkpuRWlpbzV6d1E9PSIsInZhbHVlIjoiWnZkNnFDTUNyT1dnbXRCTFFpczFFNEo2b1RTU3BMdytaR2s2S1lXSE9LMElxWmpNODBBQ3dTVUYzanZhcFdSZyIsIm1hYyI6Ijk2YmNhNWJmNjEyNDMyNGMxOThhY2RjOTUyMTQyODMxM2Y5ZGVhOThjYWQ5ZDQ5M2YzZWFhYjMxZjE2ZWJhNDYifQ%3D%3D; glidedsky_session=eyJpdiI6IlhoMDBiZ0ZQOWxpMUxSZzlhOFwvREFBPT0iLCJ2YWx1ZSI6IllBOHpBWkEyM0dYVHhrRkEzQ0ZZR01Idnh1T2xzRGViN2l3bEdPaWZkRGxOR2NKM25sUDJvUW5DYWFmM3ZZYmQiLCJtYWMiOiIxNDVjYmZhMWNmNWFiZGZlYmYwYzYyNjRjMGE3ZjI5MGNjYTZjM2Y5YThhMmNjZWM5MWFjNDRiYWJiMWZkYTY0In0%3D; Hm_lpvt_020fbaad6104bcddd1db12d6b78812f6=1587085894',}
session.headers.update(headers)
return session.get(url)
url = 'http://www.glidedsky.com/level/web/crawler-font-puzzle-1?page={}'
sum_all = 0
for i in tqdm(range(1,1001)):
html = get_cookie(url.format(str(i))).text
html_xpath = etree.HTML(html)
base64_xpath = '//style/text()'
base64_code = html_xpath.xpath(base64_xpath)[0]
base64_str = base64_code.split('base64,')[1].split(') ')[0]
b = base64.b64decode(base64_str)
with open('ttf/{}.ttf'.format(i), 'wb') as f:
f.write(b)
font = TTFont('ttf/{}.ttf'.format(i))
font_dict = {}
font_list = font.getGlyphOrder()
j = 0
last_dict = {
'zero': '0',
'one': '1',
'two': '2',
'three': '3',
'four': '4',
'five': '5',
'six': '6',
'seven': '7',
'eight': '8',
'nine': '9'
}
for i in font_list[1:]:
font_dict[last_dict[i]] = j
j += 1
number = html_xpath.xpath('//div[@class="col-md-1"]/text()')
number = [re.sub('\s+','',x) for x in number]
sum_list = []
for q in number:
s = ''
for w in q:
s+=str(font_dict[w])
sum_list.append(int(s))
# print(q,s)
sum_all +=sum(sum_list)
print(sum_all)