-
Notifications
You must be signed in to change notification settings - Fork 15
/
meghalaya.py
51 lines (48 loc) · 1.48 KB
/
meghalaya.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 6 12:53:49 2018
@author: dhingratul
"""
import time
from bs4 import BeautifulSoup
import urllib
import sys
sys.path.insert(0, '../tools/')
import utils
m_url = "http://ceomeghalaya.nic.in/erolls/erolldetails.html"
mdir = '../data/Meghalaya/'
page_url = "http://ceomeghalaya.nic.in/erolls/"
base_url = "http://ceomeghalaya.nic.in/erolls/pdf/english/"
driver = utils.getDriver(m_url)
html = driver.page_source
soup = BeautifulSoup(html, "lxml")
table = soup.find('table')
find_a = table.find_all('a', href=True)
driver.quit()
i_start = 1
j_start = 1
for i in range(i_start, len(find_a)):
const_url = page_url + find_a[i]['href']
ac = int(find_a[i]['href'].split("-")[0])
driver = utils.getDriver(const_url)
html = driver.page_source
soup = BeautifulSoup(html, "lxml")
rows = soup.findAll('tr')
driver.quit()
for j in range(j_start, len(rows)):
print("\n", i, j)
p1 = format(ac, '03d')
p2 = format(j, '04d')
suffix = "A{}/A{}{}.pdf".format(p1, p1, p2)
url = base_url + suffix
fid = suffix.replace("/", "_")
try:
flag = utils.download_file_W(url, mdir, fid)
if flag == 0:
with open("Meghalaya.txt", "a") as myfile:
myfile.write(url + '\n')
except urllib.error.HTTPError:
with open("Meghalaya.txt", "a") as myfile:
myfile.write(url + '\n')
time.sleep(2)