Home > other >  How python download url files, download files 0 KB
How python download url files, download files 0 KB

Time:10-04

Ladies and gentlemen, now I want to batch download the financial statements of listed companies, run into problems, the following is the source code:
# - * - coding: utf-8 - * -
The import requests
The from urllib. Request the import urlopen
Url="http://basic.10jqka.com.cn/api/stock/export.php? Export=main& Type=report& Code=000001 '

Def getFile (url) :
File_name=url. The split ('=') [1]
The response=requests. Get (url). The content
With the open (file_name + '. XLS ', 'wb) as f:
F.w rite (response)
Print (" Sucessful to download "+" "+ file_name)

GetFile (url)
To perform the above code, can only generate a 0 KB file, if copy the url directly into the browser address bar, enter, will pop up a window, click ok, to save to complete file,
Tried wget didn't effect,

Also tried urllib. Request.
urlretrieve methodThe import urllib. Request
Url="http://basic.10jqka.com.cn/api/stock/export.php? Export=main& Type=report& Code=000001 '
Urllib. Request. Urlretrieve (url, '000001' + '. XLS ')
As well as short of effect,
Excuse me, where is the problem?

CodePudding user response:

Web site has anti climb mechanism, please send request header

CodePudding user response:

Really need to simulate head, thank you
  • Related