Created
March 8, 2021 09:55
-
-
Save WillemJan/95c56a47643d6f49873ba656fae8155a to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
""" | |
https://opac.perpusnas.go.id/uploaded_files/dokumen_isi3/Terbitan%20Berkala/PERTJATOERAN_19[26-31]_[Januari|Februari|Maret|April|Mei|Juni|Juli|Agustus|September|Oktober|November|Desember]_03_Tahun_[III|IV|V|VI|VII]_No_[1-150]_001.pdf. | |
""" | |
import requests | |
month_names = "Januari|Februari|Maret|April|Mei|Juni|Juli|Agustus|September|Oktober|November|Desember" | |
date_range = [1926, 1931] | |
roman_numeral = "III|IV|V|VI|VII" | |
range_no = [1,150] | |
predict_url = "https://opac.perpusnas.go.id/uploaded_files/dokumen_isi3/Terbitan Berkala/PERTJATOERAN_%s_%s_03_Tahun_%s_No_%s_001.pdf" | |
for i in range(date_range[0], date_range[1]): | |
for m in month_names.split('|'): | |
for r in roman_numeral.split('|'): | |
for j in range(range_no[0], range_no[1]): | |
url = (predict_url % (str(i),m,r,str(j))).replace(' ', '%20') | |
print(url) | |
req = requests.get(url) | |
if req.status_code == 200: | |
print('Found ', url) | |
fname = url.split('/')[-1] | |
with open(fname, 'wb') as fh: | |
fh.write(req.content) | |
else: | |
print('Not found', url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment