Skip to content

Instantly share code, notes, and snippets.

@simgislab
Created April 11, 2016 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simgislab/16e51da5e846155ae00c3b40888f93ea to your computer and use it in GitHub Desktop.
Save simgislab/16e51da5e846155ae00c3b40888f93ea to your computer and use it in GitHub Desktop.
CIK RF calendar grabber
import requests
base_url = 'http://www.izbirkom.ru/izbirkom/calendar/?mode=result&date=10.03.2016&date2=10.04.2016&regions_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