本文主要是介绍python爬虫,肯德基餐厅,批量获取,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
链接:http://www.kfc.com.cn/kfccda/index.aspx,页面最下方“餐厅查询”,点击跳转
import requests
import timedef chaxun(i=1):'''查询肯德基餐厅信息'''url = "http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword"data = {"cname": "","pid": "","keyword": "杭州", # 地址可自定义"pageIndex": i, # 页码可自定义"pageSize": "10",}headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36 Edg/88.0.705.49"}res = requests.post(url=url, data=data, headers=headers)dict_page = res.textf1 = open(r"C:\Users\User\Desktop\肯德基记得给广告费.txt", "a", encoding="utf-8")# 保存路径可自定义f1.write(dict_page + "\n" * 2)time.sleep(2) # 反扒if __name__ == "__main__":for n in range(1, 11):print(f"正在查询第 {n} 页...")chaxun(n) # 导入参数print("End.")
这篇关于python爬虫,肯德基餐厅,批量获取的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!