def handle_client(request): """handle wechat event and client message""" wechat = Wechat() args = request.args # check request signature if not wechat.check_signature(args.get('signature'), args.get('timestamp'), args.get('nonce')): return '' try: wechat.parse_data(request.data) except ParseError: log.error('Parse post data error, data: %s'%str(request.data)) return '' log.debug('Request: %s'%str(request.data)) message = wechat.get_message() response = '' # normal message if isinstance(message, TextMessage): response = wechat.response_text(content=turing_robot(message.content, message.source)) elif isinstance(message, VoiceMessage): response = wechat.response_text(content=u'语音信息') elif isinstance(message, ImageMessage): response = wechat.response_text(content=u'图片信息') elif isinstance(message, VideoMessage): response = wechat.response_text(content=u'视频信息') elif isinstance(message, ShortVideoMessage): response = wechat.response_text(content=u'小视频信息') elif isinstance(message, LinkMessage): response = wechat.response_text(content=u'链接信息') elif isinstance(message, LocationMessage): response = wechat.response_text(content=u'地理位置信息') # event message elif isinstance(message, EventMessage): # 事件信息 if message.type == 'subscribe': # 关注事件(包括普通关注事件和扫描二维码造成的关注事件) if message.key and message.ticket: # 如果 key 和 ticket 均不为空,则是扫描二维码造成的关注事件 response = wechat.response_text(content=u'用户尚未关注时的二维码扫描关注事件') else: response = wechat.response_text(content=u'普通关注事件') elif message.type == 'unsubscribe': response = wechat.response_text(content=u'取消关注事件') elif message.type == 'scan': response = wechat.response_text(content=u'用户已关注时的二维码扫描事件') elif message.type == 'location': response = wechat.response_text(content=u'上报地理位置事件') elif message.type == 'click': response = wechat.response_text(content=u'自定义菜单点击事件') elif message.type == 'view': response = wechat.response_text(content=u'自定义菜单跳转链接事件') elif message.type == 'templatesendjobfinish': response = wechat.response_text(content=u'模板消息事件') if isinstance(response, unicode): response = response.encode('utf-8') log.debug('Response: %s'%response) return make_response(response)
def py_jd_product_detail(): try: driver.get(HostUrl) time.sleep(10) gun() closeAD() except Exception as e: log.error("-------详情页面打开失败,准备重试------") driver.close() py_jd_product_detail()
def py_jd_comment(): try: btn_comment = driver.find_element_by_xpath('//*[@id="detail"]/div[1]/ul/li[5]') btn_comment.click() time.sleep(3) gun() # 首次打开,保存首页内容 save_comment() try: # 打开下一页内容 btn_last_nums = driver.find_elements_by_xpath('//a[@class="ui-pager-next"]/preceding-sibling::a') btn_last_num = btn_last_nums[-1].text last_num = int(btn_last_num) print('最后一页的页码为:', last_num) for i in range(1, 1000): print("当前页码为", i) btn_next_page = driver.find_element_by_xpath('//a[@class="ui-pager-next"]') btn_next_page.click() time.sleep(5) save_comment() except Exception as e: log.error("-------爬到最后一页了------") log.error(e) except Exception as e: log.error("-------爬取失败,系统挂了,无力回天(-.-!!)------")