-
Notifications
You must be signed in to change notification settings - Fork 0
/
nomachineScraper.py
35 lines (32 loc) · 1.23 KB
/
nomachineScraper.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
import requests
#import bs4
from bs4 import BeautifulSoup
import tqdm
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def downloadNomachineDeb():
url = 'https://downloads.nomachine.com/download/?id=5'
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
# print(soup)
# #parse html and get link from id=link_download
link = soup.find(id='link_download')
#parse link and get only href
href = link.get('href')
print('Downloading '+href.split('/')[-1])
#download href file with tqdm
requests.get(href, stream=True)
response = requests.get(href, stream=True)
total_size_in_bytes= int(response.headers.get('content-length', 0))
block_size = 1024 #1 Kilobyte
progress_bar = tqdm.tqdm(total=total_size_in_bytes, unit='iB', unit_scale=True)
#with open get same name file from link
with open(href.split('/')[-1], 'wb') as file:
for data in response.iter_content(block_size):
progress_bar.update(len(data))
file.write(data)
progress_bar.close()
if total_size_in_bytes != 0 and progress_bar.n != total_size_in_bytes:
print("ERROR, something went wrong")
if __name__ == "__main__":
downloadNomachineDeb()