# -*- coding: utf-8 -*-
#coding=gbk

import threading

__author__ = 'zkqiang'
__zhihu__ = 'https://www.zhihu.com/people/z-kqiang'
__github__ = 'https://github.com/zkqiang/Zhihu-Login'

from bs4 import BeautifulSoup
import base64
import hashlib
import hmac
import json
import re
import time
from http import cookiejar
from urllib.parse import urlencode

import execjs
import requests
from PIL import Image
import sys
from scrapy.selector import Selector
import brotli
import random
import time
import re
from gm_upload import upload, upload_file
from urllib.request import urlretrieve
import os
import cv2
import copy
import traceback
import pymysql
import jieba
import jieba.analyse
import os
from gevent import monkey; monkey.patch_socket()
import gevent
from threading import Thread, Lock
import urllib.parse
import hashlib
import random


mutex_for_get_query_word = Lock()
mutex_for_zhihu_save_question_info = Lock()
mutex_for_zhihu_save_file= Lock()
g_cur_word_index = 0

g_have_spidered_query_word = [
    "嗨体祛颈纹","溶脂针瘦腿","鼻形矫正","植发5折单株¥2起","双眼皮画美","美成瓷娃娃","玻尿酸去颈纹","种植胡须","马夸特面具","轮廓三件套","瘦脸针画美","天然妈生双眼皮限时¥880","Botox","整形模拟器","下巴假体取出","额头提升","欣菲聆水光针","激光去疤","产后塑形","测脸型。","凸嘴手术","全脸打造","毛周角化","飞梭3D铒激光","激光祛痘坑","下颚角、下鄂缘","ai侧脸","身体美白","小翘鼻宝宝","眼尾下至","智美颜和","颧弓外扩","埋线除颈纹","胶原蛋白填充丰面颊","医美5院天团","身体塑形","假体隆下巴","半肋骨隆鼻","我酷固我在","人中整形","激光去黑头","嘴角下垂","郑大二附院","男士隆鼻","鼻翼外切","一生约玻尿酸","伊婉（韩国）","激光祛色素病","不开刀双眼皮","果酸祛痘","冷冻溶脂瘦大腿","四川米兰柏羽","润百颜白紫","耳部整形","粉毒（韩国）【国内未审批】","安美星河","陶瓷矫正","水光娃娃","visia","吸脂瘦肩膀","美轮美奂","法思丽丝柔","和颜美帕","都市风韵","假期变美项目清单!8折封顶","活细胞填充","我是什么脸型","奇致脂肪","男生双眼皮","fame","脸型检测","韩式生科下巴","下颚缘提升","乳房再造","美莱瘦脸针","双眼皮恢复","激光缩阴","颧骨填充术","粉毒（韩国）","斩男心机妆","少女心未泯","西区年货提前购","点阵像素激光","抗衰紧致口碑榜","口唇整形","医美面膜","肋软骨鼻综合","G点增厚","眼周射频","银盒菲洛嘉3ml特价","膨体鼻综合","按摩减肥","玻尿酸润百颜","适合的发型","明星颜值打call","上眼提肌","热玛吉5代","三庭五眼","嗨体泪沟","达美如艺","长下巴矫正","激光去痘印","娇兰玻尿酸","荔医瘦腿","河西整形","自体填充","腹部松弛","v脸套餐","鼻子缩小","眼部去脂","面部清洁","半肋骨鼻","鼻中隔延长","抽脂手臂","阴唇缩小","丽港丽格","双眼皮术后","双眼皮全切","抽脂瘦脸","男士纹眉","口腔医院","鼻头修复","激光溶脂瘦大腿","额头除皱","吸脂面部","玻尿酸去法令纹","双眼皮手术","拜博口腔","化学剥脱祛斑","新生植发","龅牙矫正","全肋隆鼻","魔镜测脸","下巴抽脂","艾菲尔隆胸","镭射双眼皮","取下巴假体","唇部脱毛","下巴溶脂","半肋鼻综合","大v脸、小v脸","爱芙莱（国产）","长曲线截骨","隆鼻、鼻部综合、鼻子","瘦脸针50","禹彤绣苑","腰部吸脂","面部精雕","四肢脱毛","缪斯女神","男性乳房肥大矫正","眼睛下至","全脸埋线提升","眼综合修复","玻尿酸垫下巴","后背吸脂","pst面部提升","特色橡皮糖","微整修复","骨性龅牙","自体血清","发型测试","私处粉嫩","脸不对称","prp水光针","玲珑梵宫","眼鼻综合","苹果肌下垂","立秀膨体","全脸吸脂","溶解玻尿酸","华西妇产","激光溶脂瘦腰腹","DRREBORN唯专","美仑美奂","脱手脚毛","什么脸型","背部祛痘","鼻假体取出","cooki","增生疤痕","Ai测脸","眼部祛皱","润致动能素","玻尿酸导入","全脸埋线","prp水光","宠物系女孩","近视手术","眼周热玛吉","prp血清","长虹钜惠首单免费","男士双眼皮","小分子玻尿酸","细胞激活","玻尿酸丰泪沟","四川娇点","润致（国产）","韩国小气泡","非剥落点阵","双眼皮开眼角","颜值测试","膨体取出","自体脂肪丰泪沟","吸脂手臂","双侧耳软骨","菲洛嘉动能素","下颌吸脂","激光溶脂瘦手臂","baby","眼下细纹","内眦赘皮","斯美诺水光针222元玻尿酸398元","肩膀吸脂","鼻翼内切","模拟整形","胸部塑身","无痕去眼袋","肉毒素+玻尿酸套餐","西区医院","爱贝芙注射","蛋白线提升","睫毛嫁接","自体脂肪下巴","去除眼部细纹","自体脂肪垫眉弓","招风耳矫正","提升式瘦脸针限时¥980","苹果肌提升","眼角提升","女性私密·必囤货","中关村医院","冷光牙齿美白","激光祛痣","哪位女明星在植发？","下巴矫正","手指整形","诠美吸脂","半永久睫毛","补水套餐","润百颜玻尿酸全城免费送！","痘坑填充","显微瘦小腿","韩版超声刀","自体脂肪填充额头","大小腿吸脂","乳房提升","瘦身套餐","Medpor垫下巴","生长因子取出","自体软骨垫鼻基底","阴蒂肥大整形","我喜欢2","双眼皮疤痕","光纤吸脂","强脉冲光祛红血丝","脂肪修复","肉毒杆菌","小阴唇整形","衡力（国产）","肉毒素除眉间纹","玻尿酸隆下巴","皮秒洗眉","半永久眼线","下睑下至","腋下脱毛","胸部套餐","海薇（国产）","八大处整形","去皮去脂","吸脂小腿","全脸分析","雪儿海蒂","眼部填充","頺。。。。谟","三点式双眼皮","东国水光针","半肋隆鼻","下巴填充","全肋骨隆鼻","自体脂肪丰卧蚕","私密飘红","自体脂肪填充黑眼圈","补单专拍","希思种植牙","玻尿酸填充太阳穴","三文鱼针","玻尿酸品牌","激光除皱","水光针年卡","激光去痘坑","下颌骨手术","硅胶隆胸","picoway","抽脂大腿","阴道成形","非剥脱点阵","面部下垂","隆鼻失败","颧骨下颌角","耳软骨鼻综合","玻尿酸注射丰乳头","长脸矫正","剖腹产疤痕","胶原蛋白注射隆鼻","鼻综合修复","颜值报告","肉毒素祛腋臭","针灸减肥","全脸脱毛","玻尿酸丰苹果肌","眼袋泪沟","框格释放","深层清洁","激光去纹身","ICL晶体植入","疤痕疙瘩","艾莉薇玻尿酸","Get迷人漫画眼","宫颈癌疫苗","鼻唇沟填充","睫毛种植","鹏爱悦己","激光脱全身毛发","米罗的小梦想","玻尿酸祛黑眼圈","膨体丰额头","颧骨手术","鹏爱秀琪","华美美莱","珠江医院","眉弓过平","日式双眼皮","埋线瘦腰腹","乔雅登（美国）","自体丰胸","祛黄褐斑","切除下颌角","乔雅登玻尿酸","激光去红血丝","迪丽热巴","耳软骨复合隆鼻","吸脂瘦腿","鹰钩鼻矫正","纳米脂肪填充","瘦身美体","全面部吸脂","吸脂双下巴","海珠水光针","卿卿呢喃","V-line瓜子脸手术","半永久唇","面部线雕提升","假体填充苹果肌","美白水光针","法思丽玻尿酸","华中科技大学同济院","脸部分析","疤痕增生","自体脂肪填充下巴","爱芙莱玻尿酸","自体脂肪填充全脸","润致玻尿酸","脸颊吸脂","小腿肌肉","川字纹脂肪填充","肉毒素瘦肩肌","硅胶垫眉弓","中国医学科学院整形外科医院","颜值分析","玻尿酸填充法令纹","隆胸修复","韩式双眼皮","飞梭镭射","奇致热玛吉","脂肪填充全脸","唇部修复","美白导入","热玛吉眼部","激光治疗敏感肌","玻尿酸苹果肌","公主玻尿酸","玻尿酸丰唇珠","自体脂肪丰全脸","v-line","告别女旱子","润百颜（国产）","埋线提升胸部","金属托槽矫正","韩式三点双眼皮","面部凹陷","美白微针","内切眼袋","瘦腿针200","颧骨缩小","手术祛疤","隆鼻¥999","阴蒂提升手术","颧骨吸脂","纳米脂肪","肉毒素去鱼尾纹","眼部细纹","强脉冲光","激光美白","眼袋手术","鼻综合画美","韩国Doublo-M超声刀","脱大小腿","丝丽StylageHydro","人中加深","眼角下垂","亚美蜜园","无创疤痕修复","汉密尔顿","像素激光","脸型分析","玻尿酸精华导入","脸部溶脂","胳膊吸脂","辉煌360","玻尿酸额头","埋线除皱","欧式双眼皮","全世界最美丽的人","双颚手术","射频溶脂瘦腰腹","眼皮吸脂","颌面正畸","割双眼皮","小腿抽脂","玻尿酸丰卧蚕","内吸眼袋","meya","玻尿酸注射套餐","埋线避孕","不开刀祛眼袋","西南医院","注射缩鼻头","眉毛种植","注射隆鼻","面部不对称矫正","自体脂肪面部年轻化","平行双眼皮","褐青色痣","吸脂去副乳","补水+塑形400起","吸脂大腿","适合发型","开外眼角下至","手术去法令纹","脸部脱毛","玻尿酸丰鼻基底","黄金微针治疗妊娠纹","膨体鼻基底","牙齿贴片","轮廓骨骼","kisskiss唇","种植牙齿","下颌缘紧致","唇部综合","脂肪填充下巴","玻尿酸卧蚕","玻尿酸垫眉弓","玻尿酸去黑眼圈","美颜相机","半永久眉毛","有针水光","王者之心","微整套餐","鼻尖延长","海微玻尿酸","激光祛纹身","全瓷贴面","玻尿酸泪沟","纳米无痕双眼皮","鼻孔重塑","注射去鱼尾纹","私密处黑","补水保湿","复合隆胸","术唯可水光针","小腿脱毛","四川军大附属","光子祛痘","法令纹填充","染料激光","菁芙水光针","新星靓整形医院","肋骨鼻修复","切除法祛副乳","视力矫正","半永久发际线","人工骨垫下巴","下颌内缩","臀部整形","大眼综合","四川美莱水光针299元","适合什么发型","私密护理","胸部形态重塑","注射物取出","ATR调Q激光","祛疤套餐","脂肪胶填充","轮廓套餐","奇致双眼皮","医用面膜","嘴唇变薄","内窥镜手术提升","嫁接睫毛","眼皮去脂","吸脂瘦身","少女针注射","吴氏嘉美","双眼皮埋线","手臂脱毛","假体丰额头","乳头漂红","品质严选机构","Fei黄金射频微针仪","激光洗眼线","超声波洁牙","射频溶脂瘦大腿","自体脂肪垫鼻基底","脂肪填充额头","黑色素沉淀","自体脂肪填充太阳穴","面部提升套餐","埋线双眼皮修复","修复双眼皮","托槽牙齿矫正","中医减肥","自体脂肪丰眼窝","隔空溶脂","异体骨隆鼻","外切眼袋","脱络腮胡","牙齿治疗","超级冰点脱毛","vline","瑞兰玻尿酸","乳房缩小","美丽焦点","手臂环吸","周二半价抢","射频溶脂瘦脸","丝丽玻尿酸","年度人气项目榜单","激光脱腋毛","艾莉薇（韩国）","拼团4折封顶！","鼻头鼻翼缩小","玻尿酸法令纹","水动力环吸","爱芙莱0.5ml","眼睛修复","丝丽（法国）","米兰柏羽","润致水光针","永久脱毛","伊丽莎白","自体真皮隆鼻","产后修复","激光祛痘印","大阴唇整形","朝天鼻矫正","眼部护理","筋膜提升","熊猫针祛黑眼圈","大脚骨矫正","半隐形矫正","膨体丰太阳穴","头发稀少","吸脂塑臀","眼部提肌","腿部抽脂","玻尿酸鼻基底","prp注射生发","铂金瑞蓝","私密线雕","热玛吉第五代","脸部测试","美白针治疗","外眼角下至","6D小脸针","取颊脂垫瘦脸","鼻孔缩小","私处漂红","你的唇型真好看","吸脂全身","颧骨颧弓整形术","清洁补水","激光点阵","激光去黑眼圈","真皮填充卧蚕","乳房悬吊术","激光除法令纹","洗牙套餐","眼部除皱","开年大促全场5折起！","韩式半永久纹发际线","超皮秒祛斑","口红王子","乳晕漂染","眼鼻专场3折起","面部测试","下巴硅胶假体取出","6d小脸针","超微小气泡","第五代热玛吉","鼻头整形","肉毒素去法令纹","溶玻尿酸","玻尿酸伊婉","美美焕新颜满899-400","腹部吸脂","全切双眼皮去皮","V-LINE瓜子脸手术","澳玛星光","硅胶丰额头","眼部整形","干细胞填充","脂肪填充太阳穴","激光治疗妊娠纹","面部不对称修复","鼻子修复","吸脂仅5折","肉毒素除鱼尾纹","包皮手术","玻尿酸鼻子","射频祛眼袋","树脂贴面","玻尿酸除颈纹","脂肪精细填充8折抢","激光祛痘","鼻尖塑形","去肿眼泡","鼻骨矫正","胸部修复","嗨体水光针","激光除颈纹","紧致提升","法思丽（台湾）","单部位吸脂","溶脂针注射","润百颜大分子","天使之翼","自体脂肪丰面颊","小忠丽格","激光祛脂肪粒","美国曼托","颏肌放松","下巴整形","眼周皱纹","下巴截骨术","双眼皮失败","爱笑的她","吸脂瘦腰部","去脂肪粒","玻尿酸除皱","纳米树脂补牙","吸脂瘦小腿","眼皮抽脂","假体鼻基底","三甲医院","bodytite","肉毒素去动态纹","脸部提升","鼻部膨体假体取出","激光脱面部其他毛发","童颜针注射","狐臭手术","疤痕软化针","假体垫下巴","光子脱毛","fotona","上睑下垂矫正","UltraShape优立塑","爆款手术全场7折起","贵族手术（假体填充法令纹）","不开刀去眼袋","变性手术","无针水光针","超声溶脂瘦小腿","眼部抗衰老","公立医院","自体脂肪填充卧蚕","戳我Get水光肌！","韩国V-Line溶脂针","面部不对称改善","双下巴吸脂","吸脂瘦腹部","阴唇整形","超皮秒激光","生长因子","PRP自体脂肪填充","韩式半永久雾眉","胶原蛋白填充祛法令纹","鼻部整形","水光针菲洛嘉","脸部不对称","翘鼻侧颜杀¥990","额头填充","眼部吸脂","胸部假体取出","唇珠唇弓成形术","激光脱比基尼部位","韩式半永久漂唇","面部脱毛","手臂抽脂","射频微针","眼窝填充","阴茎增大","嘴唇改薄","线雕鼻子","发际线低","激光脱比基尼","眼皮松弛","微针美塑","私处美白","上眼睑去脂","吸脂单部位¥494","祛斑祛痣","鼻中隔软骨垫鼻头","脂肪填充失败修复","肉毒素去川字纹","膨体垫鼻基底","下巴玻尿酸","解锁职场运！新人如何变美人？","隆鼻修复","河南整形","鼻基底填充","乳头乳晕","M唇手术","牙齿冷光美白","瘦脸针进口","衡力瘦脸针","瘦脸除皱","戳！王牌机构Top榜","抗衰紧致","眼窝凹陷","内眼角修复","荔医玻尿酸","激光祛红血丝","玻尿酸全脸填充","热玛吉五代","阴茎延长","凹陷疤痕","鼻部硅胶假体取出","日本高田美白针","肉毒素去狐臭","瑞蓝玻尿酸","榜单节5折抢！","泪沟填充","自体脂肪丰唇","美国V-Loc（薇乐）线雕","私密超声刀","根管治疗","超声波洗牙","上睑下垂","伊美名媛","疤痕修复","眼部热玛吉","乳房下垂矫正","韩式三点","肉毒注射","十二星座名医大合集","激光紧缩阴道","头发种植","异物取出","奥美定取出术","新鲜水光脸","手术缩鼻头","保妥适除皱","上眼睑祛脂","假体太阳穴","取颊脂垫","假体取出","下巴后缩","轮廓手术","定点双眼皮","颧弓降低","假体眉弓","保妥适（美国）","纹发际线","腿部吸脂","全身美白","卧蚕手术修复","线雕提升","o型腿矫正","眼部套餐","脸型测试","鼻小柱延长","祛斑套餐","酷塑冷冻溶脂","全身塑型套餐","整容医生也戏精","超声溶脂","激光溶脂祛双下巴","强脉冲激光祛雀斑","胶原蛋白填充祛黑眼圈","美白套餐","驼峰鼻矫正","牙齿整形","热门针剂买一送一","除皱套餐","膨体垫眉弓","提眉修复","自体肋软骨垫鼻基底","ai测脸","轮廓整形套餐","吸脂修复","G点注射","印第安纹","下颚角切除","去颊脂垫","吸脂瘦背部","超体隆鼻","肋骨鼻综合","下巴假体","针清祛痘","射频溶脂瘦手臂","手术祛腋臭","颧弓内推","脸部填充","宽鼻矫正（缩鼻背）","舌侧矫正","韩式生科","脸部抽脂","润百颜玻尿酸","下巴修复","情人节微整抗衰50%OFF","意大利Glutax美白针","脸型矫正","面颊吸脂","唇部套餐","笑容因齿闪耀","botox","肉毒素缩鼻头","额头缩小","青春动能素","plasma","双眼皮加宽","鼻骨内推","祛痘套餐","臀部吸脂","二氧化碳点阵","无痕双眼皮","三点双眼皮","歪鼻矫正","切开双眼皮","你的侧颜“杀”死谁","测试脸型","假体垫眉弓","下颌缘吸脂","三点定位双眼皮","英诺小棕瓶","眼角下至","凯润婷34周年庆0.5折起","一双眼拯救一张脸","元气苹果肌","Get星星眼","欧洲之星","发型设计","科发源植发无需剃发","颜值高光时刻","假体丰太阳穴","假期攻略玻尿酸328元","颧骨颧弓修复","日式无痕双眼皮","下巴截骨前移","矫正牙齿","缩小鼻翼","鼻中隔软骨隆鼻","男士私密整形","北医三院","全脸整形套餐","自体脂肪除法令纹","膨体下巴","吸脂7折再减5千>","眶隔释放","泪沟明显","隆胸套餐","手术紧缩阴道","四川华美紫馨","硅胶丰太阳穴","激光溶脂瘦脸","下颌角整形","抢5折红包直享低价>","去妊娠纹","自体脂肪丰苹果肌","假体额头","微创双眼皮","下颌缘提升","润月雅水光针","阴茎增粗","吸脂祛副乳","AI测脸","V脸套餐","下颌角手术","咬肌切除","激光脱唇毛","进口瘦脸针","开眼角修复","激光脱发际线","面部轮廓","半永久美瞳线","无痕开眼角","切开双眼皮修复","去痘印痘坑","硅胶下巴","嗨体注射","祛颊脂垫","大腿抽脂","全切双眼皮修复","腿型矫正","微针水光","下眼睑下至","人中缩短术","激光缩紧阴道","乳头内陷矫正","填充太阳穴","限时免费招募","乔雅登雅致","全脸脂肪填充","美白牙齿","菲洛嘉（法国）","手术缩鼻翼","腰腹环吸","雷达线雕","太阳穴凹陷","玻尿酸大分子","缩小毛孔","眼部抽脂","威塑吸脂","双美胶原蛋白","白瓷娃娃","全身脱毛","名医专场9折抢购","伊婉玻尿酸","水动力吸脂","肋骨隆鼻","巨乳缩小","面部溶脂","衡力肉毒素","背部吸脂","唇部整形","抽脂全身","颧骨颧弓","疤痕切除","小切口手术提升","牙齿矫正","人中缩短","四川美莱","瑞蓝2号","上睑提肌","下眼下至术","激光祛眼袋","无针线雕","去红血丝","去法令纹","美学颜究所","光纤溶脂瘦脸","全身抽脂","眼袋修复","皓齿美白","去除脏脏脸","正颌手术","全脸线雕","私处脱毛","面部抽脂","嘴角上扬术","嘴角上提术","新氧魔镜","半永久纹唇","祛痘祛痘印","隐形牙齿矫正","鼻基底凹陷","激光洗眉","胸部提升","冷冻溶脂","自体脂肪丰下巴","黄金微针","发际线种植","联合丽格","私密检测","肉毒素去抬头纹","祛红血丝","微针祛痘坑","阴唇肥大整形","海薇玻尿酸","王者之冠","种植发际线","联合丽格·台美丽格","激光祛黑眼圈","一针降颧骨","外切去眼袋","黑脸娃娃","凸嘴矫正","注射美白","月光脱毛","眶隔脂肪释放","私密嫩红","手术阴道紧缩","深蓝射频","缩小鼻头","脂肪填充修复","埋线隆鼻","妍煕整形","拒绝毛孔插秧","AI扫脸","皮秒祛斑","比基尼脱毛","内切去眼袋","舒敏之星","填充卧蚕","牙齿贴面","阴蒂整形","玻尿酸垫鼻基底","维多利亚","激光去眼袋","名医改脸型限时5折","时代天使","比基尼线脱毛","SVF-gel脂肪胶","润百颜水光针","光纤溶脂","干细胞疗法","水光针注射","三文鱼水光针","面部脂肪填充","大腿环吸","溶脂针瘦脸","自体脂肪隆鼻","乔雅登极致","吸脂祛双下巴","面部提升","脸部吸脂","毛孔粗大","嗨体去颈纹","肉毒素瘦小腿","保妥适瘦脸针","下颌角切除术","假体丰臀","线雕隆鼻","点阵激光","激光点痣","丝丽动能素","乳晕缩小","假体丰胸","手臂吸脂","玻尿酸填充丰苹果肌","脱发际线","大分子玻尿酸","面部分析","黄金微雕","菲洛嘉水光针","抽脂瘦身","种植睫毛","玻尿酸填充卧蚕","上眼睑下垂矫正","海薇M＋","去黑眼圈","手术瘦脸","韩式半永久妆","祛黑眼圈","手术法缩鼻头","颧骨降低","面部线雕","膨体垫下巴","私密脱毛","埋线减肥","鼻部综合","M唇成形术","磨骨手术","润百颜黑金","搜索项目、美购、医生","腹壁成形术","玻尿酸丰额头","射频溶脂","打倒痘痘君","耳软骨垫鼻尖","红蓝光祛痘","种植眉毛","眼部综合","瘦脸针保妥适","私处整形","鼻头缩小","男性私密","无针水光","自体脂肪全脸填充","胶原蛋白填充泪沟","蜂巢皮秒","假体垫鼻基底","韩式半永久纹眼线（美瞳线）","激光祛斑","眼部修复","埋线双眼皮","自体脂肪填充泪沟","颧骨内推","吸脂瘦脸","玻尿酸下巴","全身吸脂","切眉（提眉）","小腿吸脂","植发际线","冰点脱毛","私密漂红","脂肪填充面部年轻化","自体脂肪丰额头","上眼睑提肌无力矫正","吸脂瘦手臂","腰腹吸脂","隐形矫正","鼻翼缩小","玻尿酸丰面颊","牙齿美白","假体下巴","小腿神经阻断术","外切祛眼袋","近视矫正","开外眼角","酒窝成形术","丰胸（隆胸）","玻尿酸除法令纹","美版超声刀","阴唇漂红","收缩毛孔","玻尿酸填充泪沟","太阳穴填充","限时抢！¥200无门槛红包","厚唇改薄术","面部吸脂","韩式半永久纹眉","鼻部修复","自体脂肪丰臀","硅胶隆鼻","内切祛眼袋","吸脂瘦大腿","激光祛疤","肉毒素注射","胶原蛋白注射","冷光美白","皮秒激光","激光脱毛","乳头缩小","双眼皮修复","下颌角截骨","全切双眼皮","自体脂肪面部填充","自体脂肪填充面部","玻尿酸丰太阳穴","胶原蛋白","膨体隆鼻","射频提升","自体脂肪全面部填充","开内眼角","玻尿酸丰下巴","自体脂肪丰太阳穴","胸部下垂矫正","自体脂肪丰胸","玻尿酸丰唇","牙齿瓷贴面","假体隆鼻","自体肋软骨隆鼻","埋线提升（线雕）","大腿吸脂","肋软骨隆鼻","硅胶垫下巴","自体脂肪隆胸","耳软骨隆鼻","小阴唇手术","玻尿酸隆鼻","私密整形","玻尿酸溶解酶","毛发移植","肉毒素瘦脸","保妥适肉毒素","乳晕漂红","阴道紧缩","假体隆胸","玻尿酸注射","女性私密紧致","肉毒素除皱","处女膜修复","除皱针注射","悦己时光","苹果肌缩小","产后抽脂","除皱保妥式年卡","怎么才能变白","下眼睑提升","晗美医疗","瑞蓝波尿酸","嘉悦吸脂","五洲小气泡","痘印毛孔","迪玛丝缇","超声刀多久做一次","怎么瘦小腿","肉毒素颏肌放松","测试我是什么脸型","干细胞祛疤","等风来不如追风去","刨妇产刀口","粉嫩私处","冰点脱毛美莱","吸脂增生","嗨体除颈纹","上眼提肌无力","半永久纹眉男","胶原蛋白填充丰苹果肌","可视小切口提升","胶原注射","全切双眼皮手术拆线后的护理","泪沟溶解酶","医大四院","什么样的人适合外眼角","鼻中隔是哪","肉毒微笑","垫下巴假体","祛妊娠纹","瘦脸针军美","香奈儿水光针","瘦脸针瘦肩针","烁熙Nicolas","黄褐斑水光","超体隆鼻价格","美白针进口","hpv注射","眼部动能素","鼻翼基底缩窄","全面部提升","小颜整骨","膨体和硅胶的区别","修复妊娠纹","动画矫正","鼻翼缩小后遗症","美颜微针","别劝我吃","二附医院","Plla","水光针肉毒","纹身切除","大一大二大三大四逆袭","百达丽菲","蛋白超声刀","新星靓皮秒","肉毒素卡","水光针后多久可以化妆","分段式隆鼻","西马肉毒（德国）","口腔其他项目","玻尿酸丰额头肿","挛缩鼻修复","鼻子术后","全身吸吸","Drcici","玻尿酸三年不吸收","骨盆、私密处","嗨体注射泪沟","线雕巨星","cindy梦","脱毛腋下","自体脂肪隆胸多久能穿内衣","玉之光隆胸","西美埋线","水光针法国","玻尿酸海薇m+","水光美牙","眼俭下至","红霉素药膏和醋可以去斑吗","海岸医疗","3d打印","自体脂肪填充颈纹","异体肋骨鼻综合","丽星整形医疗机构","玻尿酸导入年卡","魔滴隆胸","鼻翼基底填充","脱毛脸上","超皮秒蜂巢","杨紫的脸","怎样找到适合自己的发型","俏脸儿丰胸","适合什么样的发型我适合什么样的发型","吸脂华美","亚美整形","下颌圆提升","牙缝修补","鼻尖缩短","瘦脸针国产和进口","伊美馨双眼皮","闪耀离子束","隔空水光","锦坤国际","线雕面部提升","超音波抽脂","shuiguangzhen","汉密尔顿瘦脸针","玻尿酸鹏爱","聚焦超声溶脂","肋骨鼻一个月后","线雕埋线提升","自体胸部","忘了爱了","清新美瞳线","洗脸手法","痘痘粉刺","医用无菌面膜","杏眼化妆","祛痘视频","幸福sy","吸脂案例招募","肉毒除皱眉头下催","槿馨果酸","注射下颚缘","骨膜贴片","吸脂套餐","微针综合","超皮秒副作用","万和隆鼻","面中部吸脂","眼部护理bio","日式雙眼皮","合生齿科","奥特曼。赛罗奥特曼。","ai智能","圣慈医疗","水光针第二天","溶脂针瘦肚子","韩式生科隆鼻材料","身体刷酸","Kybella","黄金微针提升","中国整形医院","第十二人民医院","宝俪水滴","v脸瘦脸针","扁桃体结石","伊wan","自体脂肪丰唇、玻尿酸丰唇、嘟嘟唇","小部位脱毛","美伦医院","全身溶脂","菲洛嘉除皱","性感蜜桃屁股","热玛吉胸","我太瘦了","收紧双下巴","华齿口腔","腿部激光脱毛","M22祛斑","微整5折闪购抢万元免单","鼻综合肿胀","眼袋黑眼圈","水氧祛痘","优旦口腔","面部吸脂黄金","24年专利去眼袋","全切双眼皮加开眼角","水光针配方","米嘉医疗","暖冬初夏","大腿抽脂多久恢复","如何瘦脸","多部位吸脂分几次","艺美玻尿酸","南湖整形","仁爱医院口腔科","蜕化也是美","种植小虎牙","Mini脂肪","美恩双眼皮","脱毛大腿","丝丽动能素水光针","怎么涂口红","上嘴唇改薄","沪西医院","韩式假体隆鼻","脂肪填充视频","大V线雕","水光加肉毒","光疗祛斑","胶原蛋白针","进口玻尿酸有哪些","鼻子痘坑","吸脂出血少","时光线雕","溶脂塑形","膨体假体下巴取出","yiwan","插管麻醉","廣州華美","欧华医美","小气泡年卡","明星同款","日式纹眉","甄妮医疗","眼部去皱","激光祛法令纹","水光针去皱","写日记返现","甄美直播","眼部修复美莱","超声溶脂瘦肩部","陕西友谊","超声刀毁容","清洁面膜","瘦脸针美莱","大腿内侧黑","背部果酸","鼻子发红","自体脂肪鼻子","疤痕体质玻尿酸","眼皮无力","外切眼袋面部提升","眼睛去脂","蛋白提升","美式亮瞳","同济自体","射频消融祛眼袋","提升苹果肌","瘦双下巴","自体脂肪填充消肿","润百颜白紫玻尿酸","百味精灵","隆鼻后肿","下颌角整形术","visa检测","韩国处方减肥药","动氧瘦臀部","填充眼窝多少钱","艺星纹眉","魔幻变变变","qmax","玻尿酸补水导入","艾玛医疗整形","干细胞太阳穴","傲娇小小熊","身高增高","牙齿矫正3m自锁","微针祛斑","脂肪胶填充下巴","美颜脂肪隆胸","线雕提臀","颧骨颧弓八大处","3d防真隆鼻。","林青霞颜值巅峰","烤瓷牙贴片","韩式三点式双眼皮","脸部发红","汗毛激光","自锁托槽矫正","日式无痕技术","双眼皮+下至","家用超声刀","瘦脸针日记","鼻子排异","唯韩医疗吸脂","脖子紧致","双眼皮变窄","硅胶垫山根","肉毒去法令纹","艾薇国际","半永久双眼皮","垫下巴恢复","眼睑下至恢复期","假体下巴加鼻子","韩式小V脸","胡须种植","BTLAesthetics","超声刀恢复期","自己适合的发型","美国曼托假体","鼻头矫正","九院丰胸","脂肪填充保持多久","黄金脂肪胶","华美光谷腰腹吸脂","超声祛眼袋","三次隆鼻","进口膨体材料有哪里","减肥点滴","眼角去皱","娇点整形","橙子姐妹","自体脂肪填充鼻基底","祛水痘痘印","多维彩光","如何选择发型","诠美整形医院人中缩短","胸下垂纠正","测脸型看发型","长曲线下颌角","脸颊下垂","纳米脂肪隆胸","颧骨打磨","双下颌吸脂","测试妆容","紧致肚子","南光美白针","山大二院","厚唇变薄手术视频","Picoway超皮秒","鼻综合几天可以化妆","激光腋臭","瘦脸针多久见效","辉煌420","内双双眼皮","甄美瘦脸","烤瓷牙贴面","诠美眼睑下至","Phi-C+B","点阵全脸","下颌角下颌体大","协和玻尿酸除皱","二次隆鼻","长曲线磨骨","加宽双眼皮","天姿线雕","紫馨玻尿酸","眉心凹陷","壹加壹牙齿","特百惠水杯","眼睛线雕","祛疤祛痘","超薄牙贴面","玻尿酸下班","男孩整容","眼睛脂肪填充","get迷人漫画眼","小迷糊面膜","韩式去眼袋","日系隆鼻","daly","自体脂肪填充提高颜值吗","泪沟嗨体","韩式纹眉","腰腹还吸","自体脂肪填充胸部","玻尿酸注射润百颜","嘴巴太大","加拿大迪传奇微针","眼球复位","隆鼻后多久可以化妆","溶解酶额头","私处退黑","女童理发","巴奇巴诺","隆鼻软骨","不剃发种植发际线","面部吸脂多久恢复","眼隔脂肪释放","埋线酒窝","美目尚医","眼部最好医生","铭医脱毛","复合激光","外切眼袋加眶膈释放","黄金射频微针","玻尿酸3lm","卡姿兰大眼睛","日本动刀","鼻综合局麻","华美开眼角","btl脂肪刀","仪器减肥","沈梦辰整容","自体脂肪注意事项","曼托245","超声刀射频","国产衡力","双眼皮做的时候疼不疼","水光针眼部","上唇过短","薇唯玻尿酸","伊丝玻尿酸","童颜光雕","美仑吸脂","肿眼泡日记","全脸脂肪加减","脂肪填充丰苹果肌","加强水光针","瘦肩针美立方","弹力热源","绵羊老公脸","白玉美白针","韩国整形医院","瘦脸针伯思立","华美鼻综合","景甜双眼皮","眉毛铜雀","线雕头套","下巴鼻子","额头去皱","脱毛壹加壹","唇珠修复","面部射频","鼻中隔支架","美莱点阵","鹰钩鼻矫正图片","焕美瘦脸针","芯丝翠果酸","吸脂瘦脸双下巴","爱我哟。","魔镜整形","福建医科大学","牙龈突出","艺星祛痘","植发新生","脸眼下至","耳软骨隆鼻吸收","没有鼻头","鼻子图片","下巴肉毒素","去除木偶纹","线肽水光","鼻综合国产","全品类0元","肖战王一博","口腔正畸","周周最宠","lalalala","开扇形双眼皮","爱视眼科","小气泡季卡","厚唇改薄术非凡","玻尿酸隆鼻润百颜","男士美白","怎么辨别自己的脸型","脸长适合什么发型","小气泡奥薇","双眼皮三个月","外侧人中","彩虹玻尿酸","肋骨鼻恢复","永久埋线双眼皮","芳香世家","膨体下巴异物感","切下颚角","凯润婷拔牙","美丽开始的地方","私密菲蜜莉","学化妆。","烤瓷牙矫正","切开修复","直鼻翘鼻","自体脂肪填充面部多久能敷面膜","奥利安东美白针","多肽水光","二次元穿越少女","纳米祛斑","玻尿酸丰法令纹","皮秒激光蜂巢","铭医半永久","亚美预约","天地相机","宽鼻缩窄","下颌歪斜","艾薇蓝水光针","美国进口干细胞","怎么瘦腿","韩式三段","海峡医院","火影忍者","隆鼻手术视频","面部重塑","隆鼻的种类","隆鼻和鼻综合","日式小颜整骨","去黄褐斑","做完脂肪胶填充","长虹皮秒","彭体鼻+耳软鼻子","超皮秒去㿀","百嘉丽瘦脸针","我适合什么发型？","韩辰超声刀","法国映画","线雕鼻。","‘高档化妆品瓶","水光针金源","凯尔美斯","马夸特自测","双眼皮直播","面部吸脂加填充","人中手术","in77","dcell350","cold婷","眉毛缺失","公立三级医院","艺星热玛吉","鼻子注射玻尿酸","忘记就好了","腋下淋巴排毒视频","碟羽医疗","肉毒素提眉","艾薇丽尔","私密整形菲蜜丽","检查需要做什么手术","英诺退黑","玉之光脂肪","欧燕医疗","线雕仁爱","点阵激光生长纹","悦丽汇美","小耳畸形","阴道缩紧术","诠美副乳","珈禾瘦脸针","乳晕漂色","优享国际口腔","馨妍玻尿酸","热玛吉大兴医院","眼部拆线","舒铂填充鼻基底","龙泽日盛","玉泉医院微针","瘦肩针伊莱美","热玛吉艺星","河南江禾医疗整形","仁爱膨体下巴","DAYL","溶脂针诠美","腹腔镜下行子宫肌瘤剔除术","黄金V雕","liwhy","美联致美","妍度微针","云惠美阴","王仁根酒窝","瘦脸针施尔美","皓亚口腔","外阴白斑","庐僧听雨","riVkaNxCq0","环亚国际","压线双眼皮","自体肋骨鼻综合","液体超声刀","拍照识脸","发际线2000","怎么画妆","丽天整形","prp法令纹","眼角凹陷","激光祛除纹身","happy小狮子","鼻骨骨折","缔美丽面膜","男士垫下巴","你为什么容易长胖","眼袋线雕","养猪大户李老板","日本张雨绮","玻尿酸泪沟肿","自体脂肪隆胸prp","瘦身减肥","玻尿酸填充丰法令纹","涵茜尚美","奇致除皱","英诺小脂素","怎样画眉毛","天使之翼玻尿酸","胸部照片","肉毒杆菌祛眉间纹","悬浮脱毛","祛眼袋博爱","童颜baby","点阵激光艺星","开内外眼角，眼部提升","画美医院","点阵去痘印","祛痣艺星","热玛吉三百发","点扁平疣","Dancingl","江北瑞丽门诊部","鼻基地填充","Vela","鼻子模特","CO2激光","打玻尿酸下巴","私密埋线","男生脱毛","Opt祛斑","超重吸脂","治疗痘坑","吸脂硬块","韩御星美","咖蒙整形医院","牙齿拥挤","co2点阵激光","黄色A级","激光点痣艺星","李沁孙怡撞脸","自体垫鼻基底","vc美白","活细胞疗法","敲黑板·2分钟看懂国产和进口瘦脸针啥区别","破尿酸太阳穴","粘合双眼皮","射频去痘印","江依南射频","棒棒糖切口","发令纹填充","双眼皮形状","自体脂肪隆胸吸收","愉悦医美","多维立体","有可能的夜晚里","蜂巢祛斑","www,tubpcom","高允真脸型","玻尿酸丽瑅","安徽第一人民医院","祛皱额头","侨美医疗","膨体加耳软骨","眼部消脂","下颚骨截骨","玻尿酸注射鼻基底","男生头型","耳软骨卧蚕","长虹水光针","面部线条","鼻修复硅胶","原韩整形","柏垚医疗","美贝儿瘦腿针","短鼻延长","宏康妇科","长方形脸","面部吸住","注射去腋臭","水滴形圆形对比","磨骨下巴","维美大眼睛","丰胸（隆胸）曼托","妊辰纹修复","紧致腹部","微针滚针","瘦脸针的危害","脸颊脂肪填充","下颌缘轮廓瘦脸","美白m22","自体脂肪填充川字纹","长痘痘。","贵州隆鼻","隐形牙套","黑眼圈针","脂肪填充长良","取鼻基地","陈光宇瘦脸针","全身抽脂多少钱","私处超声刀","蒜头鼻缩小","prp水光菲洛嘉","精准光子","白富美脸","日本小颜","海威大分子","切开双眼皮去皮去脂","嘴巴上提","射频溶脂面部","做单眼皮","一点双眼皮","隆鼻面诊","量子微雕","脚趾脱毛","线雕痛吗","高频瘦小腿","旁氏米粹","点阵激光祛痘印痘坑","隆胸视频","Amber","花样年华假体隆胸","瑞美整形","自体脂肪全脸填充prp","点阵激光和皮秒","脱毛比基尼","凯润婷微针","鼻头肿大"
]
top_query_list = [
"瘦脸针","双眼皮","水光针","手术面部提升","鼻翼缩小","玻尿酸","吸脂","线雕","鼻综合","光子嫩肤","瘦腿针","美白针","热玛吉","隆鼻","超声刀","脱毛","祛斑","果酸焕肤","面部吸脂","皮秒","瘦肩针","自体脂肪填充面部","牙齿矫正","微针","热拉提","鼻翼缩小","瘦脸","下巴","植发","溶脂针","点阵激光","双眼皮修复","小气泡","鼻基底","祛眼袋","隆胸","祛痘","开眼角","除皱","牙齿美白","埋线双眼皮","颧骨","下颌角","纹眉","激光脱毛","玻尿酸丰下巴","法令纹","玻尿酸隆鼻","洗牙","吸脂瘦大腿","溶脂","保妥适","黄金微针","自体脂肪填充","美白","黑眼圈","白瓷娃娃","祛疤","切开双眼皮","泪沟","光纤溶脂","磨骨","嗨体","肉毒素","丰胸（隆胸）","微针祛痘坑","激光祛斑","假体下巴","植发际线","面部提升","肋骨鼻","蜂巢皮秒","祛痘祛痘印","腰腹吸脂","瘦腿","面部填充","厚唇改薄术","下眼睑下至","溶解酶","私密","点痣","酒窝","女性私密紧致","艾莉薇","伊婉V","无针水光","自体脂肪","人中缩短","m22","激光点痣","丰唇","脸型","埋线隆鼻","埋线","收缩毛孔","黑脸娃娃","伊婉C","开外眼角","童颜针","妊娠纹"
]

# 马甲号
majia_user_list = [
"32269952","32269956","32269962","32269966","32269973","32269978","32269980","32269982","32269987","32269989","32270003","32270004","32270007","32270012","32270015","32270017","32270020","32270024","32270027","32270031","32270041","32270044","32270047","32270050","32270054","32270055","32270057","32270059","32270063","32270066","32269913","32269918","32269920","32269927","32269933","32269939","32269943","32269948","32269957","32269965","32269972","32269979","32269983","32269988","32269995","32270002","32270005","32270011","32270016","32270022","32270029","32270036","32270040","32270051","32270061","32270065","32270071","32270075","32270081","32270085","32270094","32270096","32270110","32270116","32270121","32270141","32270147","32270152","32270156","32270161","32270114","32270119","32270122","32270125","32270129","32270131","32270133","32270134","32270137","32270167","32270068","32270070","32270076","32270078","32270083","32270087","32270093","32270095","32270099","32270105","32269992","32270018","32270023","32270030","32270034","32270043","32270048","32270052","32270056","32270060"
]

g_query_word_list = list()
g_if_get_query_word = False

ZHENGXING_HOST = "172.16.30.141"
ZHENGXING_USER = "work"
ZHENGXING_PWD = "BJQaT9VzDcuPBqkd"
ZHENGXING_DATABASE = "zhengxing"


class ZhihuAccount(object):

    def __init__(self, username: str = None, password: str = None):
        self.username = username
        self.password = password

        self.login_data = {
            'client_id': 'c3cef7c66a1843f8b3a9e6a1e3160e20',
            'grant_type': 'password',
            'source': 'com.zhihu.web',
            'username': '',
            'password': '',
            'lang': 'en',
            'ref_source': 'homepage',
            'utm_source': ''
        }
        self.session = requests.session()
        self.session.headers = {
            'accept-encoding': 'gzip, deflate, br',
            'Host': 'www.zhihu.com',
            'Referer': 'https://www.zhihu.com/',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
                          '(KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36'
        }
        self.session.cookies = cookiejar.LWPCookieJar(filename='./cookies.txt')

        self.zhengxing_conn = pymysql.connect(
            host=ZHENGXING_HOST,
            user=ZHENGXING_USER,
            password=ZHENGXING_PWD,
            database=ZHENGXING_DATABASE,
            charset="utf8")
        self.zhengxing_cursor = self.zhengxing_conn.cursor()
        self.tag_words_set = set()

    def login(self, captcha_lang: str = 'en', load_cookies: bool = True):
        """
        模拟登录知乎
        :param captcha_lang: 验证码类型 'en' or 'cn'
        :param load_cookies: 是否读取上次保存的 Cookies
        :return: bool
        若在 PyCharm 下使用中文验证出现无法点击的问题，
        需要在 Settings / Tools / Python Scientific / Show Plots in Toolwindow，取消勾选
        """
        if load_cookies and self.load_cookies():
            print('读取 Cookies 文件')
            if self.check_login():
                print('登录成功')
                return True
            print('Cookies 已过期')

        self._check_user_pass()
        self.login_data.update({
            'username': self.username,
            'password': self.password,
            'lang': captcha_lang
        })

        timestamp = int(time.time() * 1000)
        self.login_data.update({
            'captcha': self._get_captcha(self.login_data['lang']),
            'timestamp': timestamp,
            'signature': self._get_signature(timestamp)
        })

        headers = self.session.headers.copy()
        headers.update({
            'content-type': 'application/x-www-form-urlencoded',
            'x-zse-83': '3_1.1',
            'x-xsrftoken': self._get_xsrf()
        })
        data = self._encrypt(self.login_data)
        login_api = 'https://www.zhihu.com/api/v3/oauth/sign_in'
        resp = self.session.post(login_api, data=data, headers=headers)
        if 'error' in resp.text:
            print(json.loads(resp.text)['error'])
        if self.check_login():
            print('登录成功')
            return True
        print('登录失败')
        return False

    def load_cookies(self):
        """
        读取 Cookies 文件加载到 Session
        :return: bool
        """
        try:
            self.session.cookies.load(ignore_discard=True)
            return True
        except FileNotFoundError:
            return False

    def check_login(self):
        """
        检查登录状态，访问登录页面出现跳转则是已登录，
        如登录成功保存当前 Cookies
        :return: bool
        """
        login_url = 'https://www.zhihu.com/signup'
        resp = self.session.get(login_url, allow_redirects=False)
        if resp.status_code == 302:
            self.session.cookies.save()
            return True
        return False

    def _get_xsrf(self):
        """
        从登录页面获取 xsrf
        :return: str
        """
        self.session.get('https://www.zhihu.com/', allow_redirects=False)
        for c in self.session.cookies:
            if c.name == '_xsrf':
                return c.value
        raise AssertionError('获取 xsrf 失败')

    def _get_captcha(self, lang: str):
        """
        请求验证码的 API 接口，无论是否需要验证码都需要请求一次
        如果需要验证码会返回图片的 base64 编码
        根据 lang 参数匹配验证码，需要人工输入
        :param lang: 返回验证码的语言(en/cn)
        :return: 验证码的 POST 参数
        """
        if lang == 'cn':
            api = 'https://www.zhihu.com/api/v3/oauth/captcha?lang=cn'
        else:
            api = 'https://www.zhihu.com/api/v3/oauth/captcha?lang=en'
        resp = self.session.get(api)
        show_captcha = re.search(r'true', resp.text)

        if show_captcha:
            put_resp = self.session.put(api)
            json_data = json.loads(put_resp.text)
            img_base64 = json_data['img_base64'].replace(r'\n', '')
            with open('./captcha.jpg', 'wb') as f:
                f.write(base64.b64decode(img_base64))
            img = Image.open('./captcha.jpg')
            if lang == 'cn':
                import matplotlib.pyplot as plt
                plt.imshow(img)
                print('点击所有倒立的汉字，在命令行中按回车提交')
                points = plt.ginput(7)
                capt = json.dumps({'img_size': [200, 44],
                                   'input_points': [[i[0] / 2, i[1] / 2] for i in points]})
            else:
                img_thread = threading.Thread(target=img.show, daemon=True)
                img_thread.start()
                capt = input('请输入图片里的验证码：')
            # 这里必须先把参数 POST 验证码接口
            self.session.post(api, data={'input_text': capt})
            return capt
        return ''

    def _get_signature(self, timestamp: int or str):
        """
        通过 Hmac 算法计算返回签名
        实际是几个固定字符串加时间戳
        :param timestamp: 时间戳
        :return: 签名
        """
        ha = hmac.new(b'd1b964811afb40118a12068ff74a12f4', digestmod=hashlib.sha1)
        grant_type = self.login_data['grant_type']
        client_id = self.login_data['client_id']
        source = self.login_data['source']
        ha.update(bytes((grant_type + client_id + source + str(timestamp)), 'utf-8'))
        return ha.hexdigest()

    def _check_user_pass(self):
        """
        检查用户名和密码是否已输入，若无则手动输入
        """
        if not self.username:
            self.username = input('请输入手机号：')
        if self.username.isdigit() and '+86' not in self.username:
            self.username = '+86' + self.username

        if not self.password:
            self.password = input('请输入密码：')

    @staticmethod
    def _encrypt(form_data: dict):
        with open('./encrypt.js') as f:
            js = execjs.compile(f.read())
            return js.call('Q', urlencode(form_data))

    def add_jieba_tag_word(self):
        try:
            tag_sql = """
                    select tag_type,name from api_tag where is_online=true;
            """

            self.zhengxing_cursor.execute(tag_sql)
            sql_tag_results = self.zhengxing_cursor.fetchall()

            for tag_item in sql_tag_results:
                tag_name = tag_item[1]
                tag_type = tag_item[0]

                jieba.add_word(tag_name)
                self.tag_words_set.add(tag_name)

        except:
            print(traceback.format_exc())

    def get_tfidf_words_from_content(self,content):
        try:
            key_tag_list = list()
            keywords_list = jieba.analyse.extract_tags(content, topK=20, withWeight=True)

            for key_item in keywords_list:
                if key_item[0] in self.tag_words_set:
                    key_tag_list.append(key_item[0])
                    if len(key_tag_list)>=5:
                        break

            return key_tag_list
        except:
            print(traceback.format_exc())
            return []

    def mutex_for_zhihu_save_question_info(self,question_answer_dict,question_id,platform_id):

        mutex_for_zhihu_save_question_info.acquire(True)
        try:
            if question_id not in question_answer_dict:
                question_answer_dict[question_id] = set()

            question_answer_dict[question_id].add(platform_id)
        except:
            print(traceback.format_exc())

        mutex_for_zhihu_save_question_info.release()



    def mutex_for_zhihu_save_file_info(self,file_fd,item_dict):

        mutex_for_zhihu_save_file.acquire(True)
        try:
            file_fd.write(json.dumps(item_dict) + "\n")
        except:
            print(traceback.format_exc())

        mutex_for_zhihu_save_file.release()


    # 知乎个人文章列表
    def test_member_article(self):
        member_article_url = "https://www.zhihu.com/api/v4/members/li-pei-rong-96/articles?include=data%5B*%5D.comment_count%2Csuggest_edit%2Cis_normal%2Cthumbnail_extra_info%2Cthumbnail%2Ccan_comment%2Ccomment_permission%2Cadmin_closed_comment%2Ccontent%2Cvoteup_count%2Ccreated%2Cupdated%2Cupvoted_followees%2Cvoting%2Creview_info%2Cis_labeled%2Clabel_info%3Bdata%5B*%5D.author.badge%5B%3F(type%3Dbest_answerer)%5D.topics&offset=40&limit=20&sort_by=created"


        resp = self.session.get(member_article_url, allow_redirects=False)
        print(10*"*")
        raw_content = brotli.decompress(resp.content)
        print(type(raw_content))

        raw_content_dict = json.loads(str(raw_content,encoding="utf-8"))
        for item in raw_content_dict["data"]:
            print(item["title"])
            print(item["content"])
            print(50*"*")


    def _dispose_content_url(self,content,img_url_list,cur_image_index,cur_word_index):
        try:
            img_dir = "./img_" + str(cur_word_index)
            if not os.path.exists(img_dir):
                os.makedirs(img_dir)

            for ori_img_url in img_url_list:
                if ori_img_url.find(".jpg") >= 0 or ori_img_url.find(".png") >= 0:
                    cur_image_index += 1

                    local_img_url_path = img_dir + "/img_" + str(cur_image_index) + ".png"
                    print(ori_img_url, local_img_url_path)

                    urlretrieve(ori_img_url, local_img_url_path)
                    local_cv2_img = cv2.imread(local_img_url_path)
                    height, weidth, channel = local_cv2_img.shape
                    local_cropped_img = local_cv2_img[0:(height - 100), 0:weidth]
                    local_cropped_img_url_path = img_dir + "/cropped_image_" + str(cur_image_index) + ".png"
                    cv2.imwrite(local_cropped_img_url_path, local_cropped_img)
                    qiniu_url = upload_file(local_cropped_img_url_path)
                    content = content.replace(ori_img_url, qiniu_url)

                    os.remove(local_img_url_path)
                    os.remove(local_cropped_img_url_path)

            return content,cur_image_index
        except:
            print(traceback.format_exc())
            return content,cur_image_index

    # 知乎搜索词搜索
    def zhihu_query_by_word(self,query_word,zhihu_spider_fd,zhihu_spider_question_fd,question_answer_dict,cur_word_index):
        try:
            cur_image_index = 0
            for begin_index in range(0, 50, 10):
                # query_by_word_url = "https://www.zhihu.com/api/v4/search_v3?t=general&correction=1&lc_idx=62&" \
                #                     "show_all_topics=0&search_hash_id=1dbb1e923a17f147356177932d1236e1&" \
                #                     "vertical_info=0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C1" + "&q=" + str(query_word) + "&offset=" + str(begin_index) + "&limit=10"

                search_hash_id = hashlib.md5(str(random.random()).encode()).hexdigest()
                query_by_word_url = "https://www.zhihu.com/api/v4/search_v3?"
                query_params_dict = {
                    "q": query_word,
                    "offset": begin_index,
                    "limit": 10,
                    "lc_idx": 22,
                    "show_all_topics": 0,
                    "search_hash_id": search_hash_id,
                    "vertical_info": "0,0,0,0,0,0,0,0,0,1",
                    "correction": 1,
                    "t": "general"
                }
                query_by_word_url += urllib.parse.urlencode(query_params_dict)

                res = self.session.get(query_by_word_url, allow_redirects=False)
                print(10 * "*")
                print(query_by_word_url)
                print(res)
                raw_content = brotli.decompress(res.content)
                print(type(raw_content))

                raw_content_dict = json.loads(str(raw_content, encoding="utf-8"))

                if "data" in raw_content_dict:
                    for data_item in raw_content_dict["data"]:
                        if data_item["type"] == "search_result":
                            try:
                                data_type = data_item["object"]["type"]
                                content = data_item["object"]["content"] if "content" in data_item["object"] else ""
                                # content = copy.deepcopy(tmp_content)
                                platform_id = str(data_item["object"]["id"])
                                user_id = random.choice(majia_user_list)
                                question_id = ""
                                have_saved_this_answer = False

                                img_url_list = re.findall('src="(.*?)"', content)
                                content, cur_image_index = self._dispose_content_url(content=content,
                                                                                     img_url_list=img_url_list,
                                                                                     cur_image_index=cur_image_index,
                                                                                     cur_word_index=cur_word_index)

                                img_url_list = re.findall('data-original="(.*?)"', content)
                                content, cur_image_index = self._dispose_content_url(content=content,
                                                                                     img_url_list=img_url_list,
                                                                                     cur_image_index=cur_image_index,
                                                                                     cur_word_index=cur_word_index)

                                if data_type == "article":
                                    title = data_item["object"]["title"]
                                    title = title.replace("<em>", "")
                                    title = title.replace("</em>", "")
                                elif data_type == "answer":
                                    title = data_item["object"]["question"]["name"]
                                    title = title.replace("<em>", "")
                                    title = title.replace("</em>", "")
                                    question_id = str(data_item["object"]["question"]["id"])

                                    if question_id not in question_answer_dict:
                                        # self.mutex_for_zhihu_save_question_info(question_answer_dict=question_answer_dict,question_id=question_id,platform_id=platform_id)
                                        question_answer_dict[question_id] = set()
                                        question_answer_dict[question_id].add(platform_id)
                                        cur_image_index = self.zhihu_answers_list_by_question(question_id,
                                                                                              question_answer_dict,
                                                                                              zhihu_spider_fd,
                                                                                              cur_image_index,
                                                                                              cur_word_index)

                                        question_item_dict = {
                                            "user_id": user_id,
                                            "platform_id": question_id,
                                            "title": title,
                                            "content": content,
                                            "type": data_type,
                                            "question_id": "",
                                            "tags": self.get_tfidf_words_from_content(content)
                                        }
                                        # self.mutex_for_zhihu_save_file_info(file_fd=zhihu_spider_question_fd,item_dict=question_item_dict)
                                        zhihu_spider_question_fd.write(json.dumps(question_item_dict) + "\n")
                                    elif platform_id not in question_answer_dict[question_id]:
                                        question_answer_dict[question_id].add(platform_id)
                                        # self.mutex_for_zhihu_save_question_info(question_answer_dict=question_answer_dict,question_id=question_id,platform_id=platform_id)
                                    else:
                                        have_saved_this_answer = True
                                else:
                                    print("type is:%s" % data_type)
                                    title = ""

                                if not have_saved_this_answer:
                                    item_dict = {
                                        "user_id": user_id,
                                        "platform_id": platform_id,
                                        "title": title,
                                        "content": content,
                                        "type": data_type,
                                        "question_id": question_id,
                                        "tags": self.get_tfidf_words_from_content(content)
                                    }
                                    # self.mutex_for_zhihu_save_file_info(file_fd=zhihu_spider_fd, item_dict=item_dict)
                                    zhihu_spider_fd.write(json.dumps(item_dict) + "\n")
                            except:
                                print(traceback.format_exc())
                                print(str(data_item))
        except:
            print(traceback.format_exc())


    # 知乎问题对应的回答列表
    def zhihu_answers_list_by_question(self,question_id,question_answer_dict,zhihu_spider_fd,cur_image_index,cur_word_index):

        for begin_index in range(0,20,10):
            # answers_list_by_question_url = "https://www.zhihu.com/api/v4/questions/" + str(question_id) + \
            #                                "/answers?include=data%5B*%5D.is_normal%2Cadmin_closed_comment%2Creward_info%2Cis_collapsed%2Cannotation_action%2Cannotation_detail%2Ccollapse_reason%2Cis_sticky%2Ccollapsed_by%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Ceditable_content%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Ccreated_time%2Cupdated_time%2Creview_info%2Crelevant_info%2Cquestion%2Cexcerpt%2Crelationship.is_authorized%2Cis_author%2Cvoting%2Cis_thanked%2Cis_nothelp%2Cis_labeled%2Cis_recognized%2Cpaid_info%2Cpaid_info_content%3Bdata%5B*%5D.mark_infos%5B*%5D.url%3Bdata%5B*%5D.author.follower_count%2Cbadge%5B*%5D.topics&" \
            #                                "sort_by=default&platform=desktop" + "&offset=" + str(begin_index) + "&limit=10"

            answers_list_by_question_url = "https://www.zhihu.com/api/v4/questions/" + str(question_id) + "/answers?"
            query_params_dict = {
                    "include": "data[*].is_normal,admin_closed_comment,reward_info,is_collapsed,annotation_action,annotation_detail,collapse_reason,is_sticky,collapsed_by,suggest_edit,comment_count,can_comment,content,editable_content,voteup_count,reshipment_settings,comment_permission,created_time,updated_time,review_info,relevant_info,question,excerpt,relationship.is_authorized,is_author,voting,is_thanked,is_nothelp,is_labeled,is_recognized,paid_info,paid_info_content;data[*].mark_infos[*].url;data[*].author.follower_count,badge[*].topics",
                    "offset": begin_index,
                    "limit": 10,
                    "sort_by": "default",
                    "platform": "desktop"
                }
            answers_list_by_question_url += urllib.parse.urlencode(query_params_dict)

            res = self.session.get(answers_list_by_question_url,allow_redirects=False)
            print(10*"*")
            raw_content = brotli.decompress(res.content)
            print(type(raw_content))

            raw_content_dict = json.loads(str(raw_content,encoding="utf-8"))

            if "data" in raw_content_dict:
                for data_item in raw_content_dict["data"]:
                    try:
                        user_id=random.choice(majia_user_list)
                        data_type = data_item["type"]
                        platform_id = str(data_item["id"])
                        data_content = data_item["content"] if "content" in data_item else ""
                        question_id = ""
                        question_title = ""
                        have_saved_this_answer = False

                        img_url_list = re.findall('src="(.*?)"', data_content)
                        data_content, cur_image_index = self._dispose_content_url(content=data_content, img_url_list=img_url_list,
                                                                             cur_image_index=cur_image_index,cur_word_index=cur_word_index)

                        img_url_list = re.findall('data-original="(.*?)"', data_content)
                        data_content, cur_image_index = self._dispose_content_url(content=data_content, img_url_list=img_url_list,
                                                                             cur_image_index=cur_image_index,cur_word_index=cur_word_index)

                        if data_type == "answer" and "question" in data_item:
                            question_id = str(data_item["question"]["id"])
                            question_title = data_item["question"]["title"]

                            if question_id not in question_answer_dict:
                                question_answer_dict[question_id] = set()
                                question_answer_dict[question_id].add(platform_id)
                                # self.mutex_for_zhihu_save_question_info(question_answer_dict=question_answer_dict,
                                #                                     question_id=question_id, platform_id=platform_id)
                            elif platform_id not in question_answer_dict[question_id]:
                                question_answer_dict[question_id].add(platform_id)
                                # self.mutex_for_zhihu_save_question_info(question_answer_dict=question_answer_dict,
                                #                                     question_id=question_id, platform_id=platform_id)
                            else:
                                have_saved_this_answer = True

                        if not have_saved_this_answer:
                            item_dict = {
                                "user_id": user_id,
                                "platform_id": platform_id,
                                "title": question_title,
                                "content": data_content,
                                "type": data_type,
                                "question_id": question_id,
                                "tags": self.get_tfidf_words_from_content(data_content)
                            }

                            zhihu_spider_fd.write(json.dumps(item_dict) + "\n")
                            # self.mutex_for_zhihu_save_file_info(file_fd=zhihu_spider_fd, item_dict=item_dict)
                    except:
                        print(traceback.format_exc())
                        print(str(data_item))

        return cur_image_index


def get_query_word():

    mutex_for_get_query_word.acquire(True)

    global g_cur_word_index

    ret_word = ""
    g_cur_word_index += 1

    try:
        # query_word = top_query_list.pop()
        global g_query_word_list
        global g_if_get_query_word
        if len(g_query_word_list) == 0 and not g_if_get_query_word:
            g_if_get_query_word = True
            offi_query_word_fd = open("/data/log/spider/test_service/offi_query_word_from_20190101_20200115.txt","r")
            for line in offi_query_word_fd:
                line = line.strip()
                line = line.strip("\r")
                line = line.strip("\t")
                line = line.strip(" ")

                query_word,query_counts = line.split("\t")
                query_word = query_word.strip()

                g_query_word_list.append(query_word)

            g_query_word_list.reverse()
            offi_query_word_fd.close()

        ret_word = g_query_word_list.pop()
    except:
        print(traceback.format_exc())
    mutex_for_get_query_word.release()

    return ret_word,g_cur_word_index


def concurrence_dispose_query_word(account_obj):
    try:
        is_run = True

        while is_run:
            query_word,g_cur_word_index = get_query_word()

            if query_word not in g_have_spidered_query_word:
                print("query_word:%s" % query_word)

                zhihu_spider_data_file = "./data/zhihu_spider_data_for_query_word_" + str(query_word) + ".txt"
                zhihu_spider_fd = open(zhihu_spider_data_file, "w")

                zhihu_spider_question_data_file = "./data/zhihu_spider_question_data_for_query_word_" + str(query_word) + ".txt"
                zhihu_spider_question_fd = open(zhihu_spider_question_data_file, "w")

                # 问题回答映射词典
                question_answer_dict = dict()

                if query_word and len(query_word)>0:
                    account_obj.zhihu_query_by_word(query_word=query_word, zhihu_spider_fd=zhihu_spider_fd,
                                        zhihu_spider_question_fd=zhihu_spider_question_fd,
                                        question_answer_dict=question_answer_dict, cur_word_index=g_cur_word_index)
                else:
                    is_run = False


                zhihu_spider_fd.close()
                zhihu_spider_question_fd.close()

    except:
        print(traceback.format_exc())


if __name__ == '__main__':

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.settings")

    account = ZhihuAccount('', '')
    account.login(captcha_lang='en', load_cookies=True)
    account.add_jieba_tag_word()
    #account.test_member_article()

    # cur_word_index = 0
    # for query_word in top_query_list:
    #     cur_word_index += 1
    #     print("query_word:%s" % query_word,flush=True)
    #     account.zhihu_query_by_word(query_word=query_word,zhihu_spider_fd=zhihu_spider_fd,zhihu_spider_question_fd=zhihu_spider_question_fd,question_answer_dict=question_answer_dict,cur_word_index=cur_word_index)


    gevent_spawn_obj_list = list()
    for cur_index in range(0,100,1):
        g_obj = gevent.spawn(concurrence_dispose_query_word,account)
        gevent_spawn_obj_list.append(g_obj)


    for g_obj in gevent_spawn_obj_list:
        g_obj.join()
