#使用fiddler抓包的方式获取数据
#使用抓包的方式获取美团外卖中某一店铺的评论数据
import requests import json import time url = 'https://www.meituan.com/meishi/api/poi/getMerchantComment?uuid=e304096b68144b558626.1557200542.1.0.0&platform=1&partner=126&originUrl=https%3A%2F%2Fwww.meituan.com%2Fmeishi%2F182465701%2F&riskLevel=1&optimusCode=1&id=182465701&userId=&offset=0&pageSize=10&sortType=1 HTTP/1.1' headers = { 'Host': 'www.meituan.com', 'Connection': 'keep-alive', 'Accept': 'application/json', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36', 'Referer': 'https://www.meituan.com/meishi/182465701/', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'zh-CN,zh;q=0.9', 'Cookie': 'uuid=e304096b68144b558626.1557200542.1.0.0; _lxsdk_cuid=16a9062a749c2-0a1072d117ecdb-6353160-100200-16a9062a74ac8; __mta=246652603.1557200547149.1557200547149.1557200639552.2; ci=357; _lx_utm=utm_source%3DBaidu%26utm_medium%3Dorganic; client-id=6b9c4320-e507-4ff1-b930-f7e2822315fc; _hc.v=d1aab7ce-9506-0b69-ad57-24d8561f556c.1557288689; lat=33.070256; lng=107.035829; _lxsdk=16a9062a749c2-0a1072d117ecdb-6353160-100200-16a9062a74ac8; _lxsdk_s=16a95a37b0e-47c-28b-f41%7C%7C6', } res = requests.get(url=url,headers=headers,verify=False) time.sleep(2) # print(res.text) js = json.loads(res.text)
#print(js) # print('='*100) # print('='*100) for i in js.values(): #print(i) # print('='*100) print('='*100) for i1 in i['comments']: #print(i1) print('='*100) print(i1['userName']) print(i1['comment']) print(i1['merchantComment'])