Created
June 13, 2023 19:36
-
-
Save septs/f0d63cb1768ee37efd230afa5a90ddf9 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 | |
import re | |
import time | |
import requests | |
RE_NONCE = re.compile(r"time=(\d+\.\d+)") | |
RE_INDEX = re.compile(r"\('(\d+)'\)\"\s*>(.+)</a>") | |
DOWNLOAD_PAGE = "http://www.irouteros.com/download.php" | |
def get_name_list(): | |
response = requests.get(DOWNLOAD_PAGE) | |
return RE_INDEX.findall(response.text) | |
def get_nonce(session: requests.Session): | |
response = session.get(DOWNLOAD_PAGE) | |
matched = RE_NONCE.search(response.text) | |
if not matched: | |
return | |
return matched.groups()[0] | |
def task(index: int, saved_filename: str): | |
session = requests.session() | |
nonce = get_nonce(session) | |
time.sleep(10) | |
response = session.get(DOWNLOAD_PAGE, params={ | |
"act": "down", | |
"id": index, | |
"time": nonce, | |
}) | |
with open(saved_filename, "wb") as fp: | |
fp.write(response.content) | |
def main(): | |
for index, filename in get_name_list(): | |
print("Started %r" % filename) | |
task(index, filename) | |
print("End") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment