Last active
June 24, 2020 10:32
This file contains hidden or 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/python3 | |
import json | |
import uuid | |
import lxml.html | |
import requests | |
def main(): | |
""" | |
Displays URLs for Windows 10 ISO download from Microsoft. | |
""" | |
sessionId = uuid.uuid4() | |
r = requests.get( | |
'https://www.microsoft.com/en-us/software-download/windows10ISO') | |
root = lxml.html.fromstring(r.text) | |
downloadPageId = root.xpath('//div[@id="SoftwareDownload_DownloadLinks"]/' | |
'@data-defaultpageid')[0] | |
languagePageId = root.xpath('//div[@id="SoftwareDownload_' | |
'LanguageSelectionByProductEdition"]/' | |
'@data-defaultpageid')[0] | |
# Get skuId of English | |
r = requests.post('https://www.microsoft.com/en-us/api/' | |
'controls/contentinclude/html?' | |
f'pageId={languagePageId}' | |
'&host=www.microsoft.com&' | |
'segments=software-download,windows10ISO' | |
'&query=&action=getskuinformationbyproductedition' | |
f'&sessionId={sessionId}' | |
'&productEditionId=1626&sdVersion=2') | |
root = lxml.html.fromstring(r.text) | |
for option in root.xpath('//option'): | |
if option.text == 'English': | |
skuId = json.loads(option.get('value'))['id'] | |
break | |
r = requests.post('https://www.microsoft.com/en-us/api/' | |
'controls/contentinclude/html?' | |
f'pageId={downloadPageId}' | |
'&host=www.microsoft.com&' | |
'segments=software-download,windows10ISO' | |
'&query=&action=GetProductDownloadLinksBySku' | |
f'&sessionId={sessionId}' | |
f'&skuId={skuId}&language=English&sdVersion=2') | |
root = lxml.html.fromstring(r.text) | |
for url in root.xpath('//div[@class]/a/@href'): | |
print(url) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment