python数据采集入门,轻易拿捏!!

import requests

import random

import pandas as pd

import time

url='https://api-ddc-wscn.awtmt.com/market/kline?prod_code=CN10YR.OTC&tick_count=1500&period_type=86400&fields=tick_at%2Copen_px%2Cclose_px%2Chigh_px%2Clow_px&timestamp=1668816001&adjust_price_type=forward'

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36'}

res=requests.get(url,headers=headers).text

content=eval(res)

c1=content.get('data');c2=c1.get('candle');c3=c2.get('CN10YR.OTC');c4=c3.get('lines')

df=pd.DataFrame(c4)

df.columns=['开','收','高','低','日期']

pd.set_option('display.unicode.ambiguous_as_wide', True)

pd.set_option('display.unicode.east_asian_width', True)

times=[]

for i in range(0,len(c4)):

    e=time.strftime("%Y-%m-%d",time.localtime(c4[i][4]))

    times.append(e)

df['日期']=times

print(df)

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值