Download a file providing username and password using Python

前端 未结 2 733
名媛妹妹
名媛妹妹 2020-12-18 09:18

My file named as \'blueberry.jpg\' begins downloading, when I click on the following url manually provided that the username and password are typed when asked: http://exampl

2条回答
  •  有刺的猬
    2020-12-18 09:29

    I'm willing to bet you are using basic auth. So try doing the following:

    import urllib.request
    
    url = 'http://username:pwd@example.com/blueberry/download'
    
    data = urllib.request.urlopen(url).read()
    
    fo = open('E:\\quail\\' + url.split('/')[1] + '.jpg', 'w')
    print (data, file = fo)
    
    fo.close()
    

    Let me know if this works.

提交回复
热议问题