import requests
import json
if name == "main":
#1.指定url
post_url='http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
# 2.进行UA伪装
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
}
word=input('请输入需要查询的城市:')
params={
'cname':'',
'pid':'',
'keyword': word,
'pageIndex': '1',
'pageSize':'10'
}
#请求发送
response=requests.post(url=post_url,params=params,headers=headers)
#获取响应数据
dic_page=response.text
# 持久化储存
# page=word+'.html'
# fp=open(page,'w',encoding='utf-8')
# fp.write(dic_page)
# a=0
# for total in dic_page['Table']:
# total['rowcount']
#
print(dic_page)
a=dic_page['Table']
print(a)
报错的是: a=dic_page['rowcount']
TypeError: string indices must be integers
我想获取 dic_page字典 里面关于Table的数据