Python interface automation 22-download file (Excel)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.