Objective
Content-type type is octets/stream, this is generally a file type, such as sometimes need to export Excel data, download Excel this scenario how to use Python to implement it?
Grab Download interface
1. Download the scene as
2. Use the Fiddler tool to grab the bag, first find the Export button, click the export time to grab the packet
3.fiddler captured data as follows (response is normal, the file type is not displayed in the tool, the tool only shows the characters)
Code implementation
1. Generate Excel path, if not specified, will generate in the current script in the same directory, if specified, modify the first parameter in open: "Yoyo.xls"
2.excel suffix some computers. xls may not open, change to. xlsx
3. Both code Python2 and Python3 apply
4. Reference Code
#Coding:utf-8ImportRequestsurl='http://www.xxx.com/xxx/xxx?begNy=&endNy='Herder= { "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-language":"zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3", "accept-encoding":"gzip, deflate", "Cookies":"The cookies you caught", "Connection":"keep-alive"}r= Requests.get (URL, headers=Herder)#Open Excel file, save as file suffix xlsfp = open ("Yoyo.xls","WB") Fp.write (r.content) fp.close ()
Python interface automation 22-download file (Excel)