我正在尝试在web中抓取csv文件。 在网页中下载文件是有效的。此外,此代码在本地环境(Windows)中运行良好。 但是,当我在服务器环境(Ubuntu)中执行代码时,它不会返回任何内容,如下所示。我怎样才能解决这个问题?我想不出是什么问题
def get_otp(bld, date):
url="http://marketdata.krx.co.kr/contents/COM/GenerateOTP.jspx"
header={'Referer': 'http://marketdata.krx.co.kr/mdi', "User-Agent": "Mozilla/5.0",
"X-Requested-With": "XMLHttpRequest"}
bld= "MKD/13/1302/13020101/mkd13020101"
param={"name": "fileDown", "filetype" : "csv", "url": bld, "market_gubun": 'ALL',
"sect_tp_cd": "ALL","schdate": date,
"pagePath": "/contents/MKD/13/1302/13020101/MKD13020101.jsp"}
return requests.get(url, headers=header, params=param).text
def get_file(otp):
url="http://file.krx.co.kr/download.jspx?"
header={"Origin": "http://marketdata.krx.co.kr",
'Referer': 'http://marketdata.krx.co.kr/mdi',
"Upgrade-Insecure-Requests": "1",
"Host": "file.krx.co.kr",
"User-Agent": "Mozilla/5.0"}
param={'code':otp}
byte_data = requests.post(url, headers=header, data=param)
data=byte_data
#df = pd.read_csv(BytesIO(byte_data))
return data
bld= "MKD/13/1302/13020101/mkd13020101"
otp=get_otp(bld,"20201116")
ret=get_file(otp)
ret.heaers
结果
{'Date': 'Thu, 19 Nov 2020 08:37:01 GMT',
'Set-Cookie': 'SCOUTER=z368kb97coovj; Expires=Tue, 07-Dec-2088 11:51:08 GMT, JSESSIONID=9AC74CC81C757D3CD656EA4FD0D3A05D.102tomcat4; Path=/; HttpOnly',
'Content-Length': '0',
'Content-Type': 'text/html;charset=UTF-8'}
在更改为适用于我的示例的
bld
和pagePath
并将基本url从http://marketdata.krx.co.kr
更改为https://global.krx.co.kr
之后,我让它开始工作相关问题 更多 >
编程相关推荐