-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget-win-iso-url.py
56 lines (47 loc) · 1.68 KB
/
get-win-iso-url.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
52
53
54
55
56
import sys, time
from selenium import webdriver
selectEdition = """
options = Array.from(document.querySelectorAll('#product-edition option'));
optionToSelect = Math.max.apply(null, options.map(o => o.value));
options.filter(o => o.value == optionToSelect)[0].selected=true;
"""
selectLanguage = """
options = Array.from(document.querySelectorAll('#product-languages option'));
options.filter(o => o.value.includes('"English"'))[0].selected=true;
"""
def get_url():
if len(sys.argv) < 2:
print('No version supplied to script! Use 10 or 11 argument')
sys.exit(1)
return
elif sys.argv[1] == '10':
return 'https://www.microsoft.com/en-us/software-download/windows10ISO'
elif sys.argv[1] == '11':
return 'https://www.microsoft.com/en-us/software-download/windows11'
else:
print('Invalid version supplied to script! Use 10 or 11 argument')
sys.exit(1)
def main():
url = get_url()
options = webdriver.firefox.options.Options()
options.headless = True
profile = webdriver.FirefoxProfile()
browser = webdriver.Firefox(profile, options=options)
link = ''
try:
browser.get(url)
time.sleep(5)
browser.execute_script(selectEdition)
browser.find_element_by_id('submit-product-edition').click()
time.sleep(5)
browser.execute_script(selectLanguage)
browser.find_element_by_id('submit-sku').click()
time.sleep(5)
link = browser.find_element_by_partial_link_text('64-bit').get_attribute('href')
time.sleep(5)
finally:
browser.quit()
print(link)
sys.exit(1 if len(link) == 0 else 0)
if __name__ == '__main__':
main()