- paste
python
- 2023-4-19 1:14:25 @
import json
import warnings
import requests
import pandas as pd
headrs = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"
}
parm = {
"m": "QueryData",
"dbcode": "csyd",
"rowcode": "reg",
"colcode": "sj",
"wds": '[{"wdcode":"zb","valuecode":"A01080S"}]',
"dfwds": '[{"wdcode":"sj","valuecode":"202302"}]',
"k1": '1681834879542'
}
url = 'https://data.stats.gov.cn/easyquery.htm'
warnings.filterwarnings('ignore')
r = requests.get(url=url,params=parm,headers=headrs,verify=False)
r.encoding = 'utf-8'
tdata = json.loads(r.text)
city_list = []
for item in tdata['returndata']['wdnodes'][1]['nodes']:
city_list.append(item['cname'])
city_num = []
for item in tdata['returndata']['datanodes']:
city_num.append(str(item['data']['strdata']))
print(len(city_list))
print("----------------")
print(len(city_num))
df = pd.DataFrame({
"城市名":city_list,
"新建商品住宅销售价格指数":city_num
})
df.to_csv("70个大中城市商品住宅销售价格.xls", index=False,encoding="utf-8-sig")
0 comments
No comments so far...