cx847456739
cx847456739
2021-01-13 10:42

python爬虫请求后 response.text的内容是 -1000,

  • python
  • json
  • ajax
import requests
import json
if __name__ == "__main__":
    url='http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx'
    #UA伪装
    headers = { 
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'
    }
    city = input('enter a city:')
    page = input('enter the number of page:')
    #参数
    data = {
        'cname': '',
        'pid': '',
        'keyword': city,
        'pageIndex': page,
        'pageSize': '10',
    }
    #发送请求并接受
    response =requests.post(url=url,data=data,headers = headers)
    print(type( response))
    page_text = json.dumps(response.text)
    with open('./KFC.json','w',encoding='utf-8') as fp:
        json.dump(page_text,fp=fp,ensure_ascii=False)
    print(type(page_text))
    print(page_text)
    

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

6条回答