Skip to content

Instantly share code, notes, and snippets.

@drizzt
Last active June 24, 2020 10:32
Show Gist options
  • Save drizzt/6d9d371ca4ce80f7c47d0812ad874f14 to your computer and use it in GitHub Desktop.
Save drizzt/6d9d371ca4ce80f7c47d0812ad874f14 to your computer and use it in GitHub Desktop.
#!/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