def getFreeDineList(page, stype, user): url = 'https://m.dianping.com/activity/static/list?page={0}&cityid=7®ionParentId=0®ionId=0&type={1}&sort=0&filter=1&token={2}'.format( page, stype, user["token"]) actList = [] try: # logger.debug(url) response = request.openUrl(url, user, {}) content = str(response.read(), 'utf-8') decodeContent = json.loads(content) logger.debug(content) for act in decodeContent["data"]["mobileActivitys"]: actList.append({ "id": str(act["offlineActivityId"]), "name": act["title"], "mode": act["mode"] }) except Exception as ex: logger.error("获取霸王餐列表报错, url:{0}".format(url)) logger.error(content) logger.error(ex) logger.info('---获取第{0}页,type:{2}霸王餐, size:{1}---'.format( page, len(actList), stype)) return actList
def signUpFreeDine(dine, user, stype): data = get_request_data(dine, user, stype) url = 'http://s.dianping.com/ajax/json/activity/offline/saveApplyInfo' user["headers"].update({ "Host": "s.dianping.com", "Referer": "http://s.dianping.com/event/" + dine["id"] }) try: response = request.openUrl(url, user, data) content = str(response.read(), 'utf-8') decodeContent = json.loads(content) resultCode = decodeContent["code"] logger.info("-----霸王餐:{0}-----".format(dine["name"])) if (resultCode == 200): logger.info('-----报名成功-----') else: errMessage = decodeContent["msg"]["html"] logger.info('-----报名失败:{0},{1}-----'.format( resultCode, errMessage)) except Exception as ex: logger.error('--------报名中断报错------') logger.error(content) logger.error(ex)
def getSuccessSaveFreeDine(user): url = 'http://m.dianping.com/mobile/event/mine?source=null' setQueryHeader(user) response = request.openUrl(url, user, {}) content = response.read() soup = BeautifulSoup(content, "html.parser") logger.info('------成功报名的霸王餐------') for lind in soup.find_all('span'): if "title" in str(lind): logger.info(lind.get_text(strip=True))