工具:
if__name__=="__main__":#main#数据分析pandas自动化办公的datetime=pd.period_rangefordateindatetime:maindf=pd.DataFrameprintdf.to_excel
使用Python爬取数据目标流程为:获取证券代码、证券简称、交易日期、开盘价、最高价、最低价、收盘价、成交数量难点:请求头参数mcode加密生成使用第三方库:
defMCODE:jscode="""functionmissjson{varkeyStr="ABCDEFGHIJKLMNOP"+"QRSTUVWXYZabcdef"+"ghijklmnopqrstuv"+"wxyz0123456789+/"+"=";varoutput="";varchr1,chr2,chr3="";varenc1,enc2,enc3,enc4="";vari=0;do{chr1=input.charCodeAt;chr2=input.charCodeAt;chr3=input.charCodeAt;enc1=chr1>>2;enc2=<<|;enc3=<<|;enc4=chr3&63;if){enc3=enc4=64;}elseif){enc4=64;}output=output+keyStr.charAt+keyStr.charAt+keyStr.charAt+keyStr.charAt;chr1=chr2=chr3="";enc1=enc2=enc3=enc4="";}while;
谷歌浏览器pycharmpython7爬取到的股票数据存入到code.xlsx,可设定需要爬取的时间范围
code_list=[]
文章为作者独立观点,不代表股票交易接口观点