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.

Revisions

  1. drizzt created this gist Jun 24, 2020.
    52 changes: 52 additions & 0 deletions win10-urls.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    #!/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()