美团数据采集
import json import requests headers = { "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36", "Host": "apimobile.meituan.com", "Origin": "https://sh.meituan.com", "Referer": "https://sh.meituan.com/jiankangliren/c76/pn3/", "cookie": "uuid=7d2aafa238ee4612aa1b.1628841683.1.0.0; _lxsdk_cuid=17b3e87ac8bc8-0439c46fc4e8e-45410429-232800-17b3e87ac8cc8; mtcdn=K; userTicket=vRpNBghrqYEgwbQAMdqZJjlaRSJfFTTuHqVIZFEG; u=1782900880; n=%E6%9F%B3%E5%8D%BF.; lt=os1Vk9j5ZezoRGVSqGzTKVziBFMAAAAATQ4AAGB5A1KVP_53WXEv3MUbSNPmAfNXPPcdU8mhZoosjqwcOMvQngLdTj-i0zs_nszTjA; mt_c_token=os1Vk9j5ZezoRGVSqGzTKVziBFMAAAAATQ4AAGB5A1KVP_53WXEv3MUbSNPmAfNXPPcdU8mhZoosjqwcOMvQngLdTj-i0zs_nszTjA; token=os1Vk9j5ZezoRGVSqGzTKVziBFMAAAAATQ4AAGB5A1KVP_53WXEv3MUbSNPmAfNXPPcdU8mhZoosjqwcOMvQngLdTj-i0zs_nszTjA; lsu=; token2=os1Vk9j5ZezoRGVSqGzTKVziBFMAAAAATQ4AAGB5A1KVP_53WXEv3MUbSNPmAfNXPPcdU8mhZoosjqwcOMvQngLdTj-i0zs_nszTjA; ci=10; rvct=10; firstTime=1628842456220; unc=%E6%9F%B3%E5%8D%BF." } urltem = "https://apimobile.meituan.com/group/v4/poi/pcsearch/10?uuid=7d2aafa238ee4612aa1b.1628841683.1.0.0&userid=1782900880&limit=32&offset=%s&cateId=21004&token=os1Vk9j5ZezoRGVSqGzTKVziBFMAAAAATQ4AAGB5A1KVP_53WXEv3MUbSNPmAfNXPPcdU8mhZoosjqwcOMvQngLdTj-i0zs_nszTjA&areaId=-1" ret = [] i = 0 for i in range(30): res = requests.get( url=urltem % (i * 32), headers=headers ) print(res.text) data = json.loads(res.text) searchResult = data["data"]["searchResult"] if len(searchResult) == 0: break for obj in searchResult: ret.append({ "title": obj["title"], "avgscore": obj["avgscore"], "comments": obj["comments"], "address": obj["address"], "phone": obj["phone"], }) with open("e:\\ret.log", "a", encoding="utf-8") as f: json.dump(ret, f, ensure_ascii=False)