File download via Post form

后端 未结 2 1594
再見小時候
再見小時候 2021-01-12 23:23

There is a website that has a list of files that I want to download. To ease the process I tried to write a script to do it for me. (Even though I can select multiple option

相关标签:
2条回答
  • 2021-01-12 23:45

    The line:

    req = urllib2.Request('webpage/list.php')
    

    is requesting the original web page, but the form posts data to webpage/data.php. Does this work better?

    req = urllib2.Request('webpage/data.php')
    
    0 讨论(0)
  • 2021-01-12 23:46

    You should look into using the 'requests' library: http://docs.python-requests.org/en/latest/

    I believe this would be accomplished like this using the requests library:

    data={'data[]':'downloadable_file1.tar'}
    req = requests.post('webpage/data.php', data)
    with open('file.data', 'wb') as file:
        file.write(req.content)
    
    0 讨论(0)
提交回复
热议问题