代码拉取完成,页面将自动刷新
同步操作将从 RStata 团队/tidyfriday 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
*! 微信公众号 RStata
*! 2020 年 5 月 22 日
cap prog drop cnstock2
prog def cnstock2
version 7.0
di in yellow "下载中..."
qui{
clear
copy "http://stockdata.stock.hexun.com/gszl/data/jsondata/jbgk.ashx?count=5000&titType=null&page=1&callback=hxbase_json15" "temp.json", replace
cap erase temp2.json
mata: file()
* 处理 json 格式的数据
* 转码
unicode encoding set gb18030
unicode translate "temp2.json"
unicode erasebackups, badidea
gen str100 Stockname = ""
gen str100 Pricelimit = ""
gen str100 lootchips = ""
gen str100 shareholders = ""
gen str100 Institutional = ""
gen str100 Iratio = ""
gen str100 district = ""
gen str100 Cprice = ""
gen str200 maincost = ""
insheetjson Stockname Pricelimit lootchips shareholders Institutional Iratio district Cprice maincost using "temp2.json", table(list) col("Stockname" "Pricelimit" "lootchips" "shareholders" "Institutional" "Iratio" "district" "Cprice" "maincost")
replace district = ustrregexs(1) if ustrregexm(district, ">(.*)<")
replace maincost = ustrregexs(1) if ustrregexm(maincost, `"'>(.*)</a"')
foreach i of varlist _all {
replace `i' = "" if `i' == "--"
}
compress
destring, replace
cap erase temp.json
}
di in green "获取成功..."
end
mata:
void file() {
fin = fopen("temp.json", "r")
line = fread(fin, 3000000)
line = subinstr(line, `"'"', `"""', .)
line = subinstr(line, `""_blank""', `"'_blank'"', .)
line = subinstr(line, `"openshowd(this,""', "", .)
line = subinstr(line, `"","1")"', "", .)
line = subinstr(line, `""Closed(this)""', "", .)
line = subinstr(line, `"<img alt="" src=""', "", .)
line = subinstr(line, `""/>"', "", .)
line = subinstr(line, "sum", `""sum""', .)
line = subinstr(line, "list", `""list""', .)
line = subinstr(line, "Number", `""Number""', .)
line = subinstr(line, "StockNameLink", `""StockNameLink""', .)
line = subinstr(line, "Stockname", `""Stockname""', .)
line = subinstr(line, "Pricelimit", `""Pricelimit""', .)
line = subinstr(line, "lootchips", `""lootchips""', .)
line = subinstr(line, "shareholders", `""shareholders""', .)
line = subinstr(line, "Institutional", `""Institutional""', .)
line = subinstr(line, "Iratio", `""Iratio""', .)
line = subinstr(line, "deviation", `""deviation""', .)
line = subinstr(line, "maincost", `""maincost""', .)
line = subinstr(line, "district", `""district""', .)
line = subinstr(line, "Cprice", `""Cprice""', .)
line = subinstr(line, "Stockoverview", `""Stockoverview""', .)
line = subinstr(line, "hyLink", `""hyLink""', .)
line = subinstr(line, "dyLink", `""dyLink""', .)
line = subinstr(line, "gnLink", `""gnLink""', .)
line = subinstr(line, "StockLink", `""StockLink""', .)
line = subinstr(line, "Addoptional", `""Addoptional""', .)
line = subinstr(line, "hxbase_json15(", "", .)
line = subinstr(line, "}]})", "}]}", .)
fclose(fin)
fout = fopen("temp2.json", "w")
fwrite(fout, line)
fclose(fout)
}
end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。