Created
April 11, 2016 08:04
-
-
Save simgislab/16e51da5e846155ae00c3b40888f93ea to your computer and use it in GitHub Desktop.
CIK RF calendar grabber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
base_url = 'http://www.izbirkom.ru/izbirkom/calendar/?mode=result&date=10.03.2016&date2=10.04.2016®ions_code[]=all&old_regions_code[]=all&sxemavib[]=all&urovproved[]=all&vidvibref[]=all&vibtype[]=all' | |
r = requests.get(base_url) | |
r.encoding = 'windows-1251' | |
res = r.text.replace('</td><td ','</td>\r<td ') | |
res = res.split('\r') | |
f_out = open('calendar.html','wb') | |
cnt = 1000 | |
for line in res: | |
line = line.replace('\n','') | |
#get cound | |
if 'result_count' in line: | |
cnt = int(line.split('</div>')[0].split(' ')[-1]) | |
if cnt > 300: | |
if 'autocomplete="off"' not in line: | |
f_out.write(line.encode('utf-8') + '\n') | |
else: | |
line = line.replace('</table><input type="hidden" id="result_no" value="300" autocomplete="off">','') | |
f_out.write(line.encode('utf-8') + '\n') | |
break | |
else: | |
print 'no need' | |
headers = {'Content-Type': 'application/x-www-form-urlencoded'} | |
if cnt > 300: | |
attempts = cnt/300 | |
for num in range(attempts): | |
r = requests.post(base_url, data = {'getresult':(num+1)*300}, headers=headers) | |
r.encoding = 'utf-8' | |
res = r.text.replace('</td><td ','</td>\r<td ') | |
res = res.split('\r') | |
for line in res: | |
f_out.write(line.encode('utf-8') + '\n') | |
f_out.write('</table><input type="hidden" id="result_no" value="300" autocomplete="off"><div class="more_button"></div></div></body></html>'.encode('utf-8')) | |
f_out.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment