get_app_pdd__data_5.py 142 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979
  1. import requests
  2. import base64
  3. # import cv2
  4. import uiautomator2 as u2
  5. import time
  6. import subprocess
  7. import re
  8. import random
  9. import datetime
  10. import json
  11. from apscheduler.schedulers.blocking import BlockingScheduler
  12. from aip import AipOcr
  13. import numpy as np
  14. import cv2
  15. import os
  16. from pdd_config import Config
  17. import logging
  18. from logger import setup_logger
  19. import xml.etree.ElementTree as ET
  20. import secrets
  21. setup_logger("pdd_spider") # 初始化日志
  22. def get_access_token():
  23. AppKey = Config.APP_KEY
  24. AppSrcret = Config.APP_SECRET
  25. token_url = Config.token_url
  26. url = f"{token_url}?grant_type=client_credentials&client_id={AppKey}&client_secret={AppSrcret}"
  27. payload = ""
  28. headers = {
  29. 'Content-Type': 'application/json',
  30. 'Accept': 'application/json'
  31. }
  32. response = requests.request("POST", url, headers=headers, data=payload)
  33. try:
  34. return response.json()['access_token']
  35. except:
  36. return None
  37. def get_mysql():
  38. """
  39. 建立并返回一个到数据库的连接对象
  40. """
  41. import pymysql
  42. return pymysql.connect(
  43. host=Config.DB_HOST, # "localhost", # 修改后的主机
  44. port=Config.DB_PORT, # 3306, # 添加端口号
  45. user=Config.DB_USER, # 'root', # 修改后的用户名
  46. password=Config.DB_PASSWORD, # 修改后的密码
  47. db=Config.DB_NAME, # "drug_data", # 修改后的数据库名
  48. charset='utf8mb4'
  49. )
  50. # 获取滑块验证中滑块需要移动的距离
  51. def slide_verify(img_path):
  52. with open(img_path, 'rb') as f:
  53. b = base64.b64encode(f.read()).decode() ## 图片二进制流base64字符串
  54. url = "http://api.jfbym.com/api/YmServer/customApi"
  55. data = {
  56. ## 关于参数,一般来说有3个;不同类型id可能有不同的参数个数和参数名,找客服获取
  57. "token": "1nDVocTE2mJ0yLEYb2sZJ5uUY2VIEoGTkIpW44X7Kgk",
  58. "type": "22222",
  59. "image": b,
  60. }
  61. _headers = {
  62. "Content-Type": "application/json"
  63. }
  64. response = requests.request("POST", url, headers=_headers, json=data).json()
  65. print(response)
  66. if response.get("msg") == "识别成功":
  67. # 获取 data 中的 data 字段
  68. result = response.get("data", {}).get("data")
  69. if result:
  70. print(result) # 输出结果
  71. else:
  72. print("无法获取数据")
  73. else:
  74. print("识别未成功")
  75. return result
  76. class PDD:
  77. def __init__(self, search_key, device_id):
  78. self.package_name = 'com.xunmeng.pinduoduo'
  79. self.APP_ID = '116857964'
  80. self.API_KEY = '1gAzACJOAr7BeILKqkqPOETh'
  81. self.SECRET_KEY = 'ZNArANb9GwJYgLKg4EfYhukKBfPdl1n3'
  82. self.client = AipOcr(self.APP_ID, self.API_KEY, self.SECRET_KEY)
  83. # self.city2province = self.get_city_info()
  84. # host = "localhost"
  85. # user = "root"
  86. # password = "dfwy2025"
  87. # database = "drug_data"
  88. # port = 3306
  89. # self.table_name = "mt_drug"
  90. self.table_name = Config.DB_PDD_TABLE # "pdd_drug"
  91. self.shop_table_name = Config.DB_PDD_SHOP_TABLE # "pdd_shop_info"
  92. self.loggerPdd = logging.getLogger()
  93. self.clipboard = "" # 初始化剪切板的内容为空
  94. self.access_token = get_access_token()
  95. self.search_key = search_key # 参苓健脾胃颗粒 香砂平胃颗粒 舒肝颗粒 清肺化痰丸
  96. self.unrelated_data = 0 # 无关数据数量
  97. self.device_id = device_id
  98. #统计售罄数量
  99. self.sold_out_counts = 0
  100. # 程序启动时间
  101. self.program_start_time = self.app_start_time()
  102. #统计商品数量
  103. #最大量数据阈值
  104. self.max_counts = 0
  105. #统计点击商品的次数
  106. self.click_counts = 0
  107. #商品在列表的位置
  108. self.search_key_loc = 0
  109. # oss配置
  110. self.oss_config = {
  111. "access_key_id": Config.access_key_id,
  112. "access_key_secret": Config.access_key_secret,
  113. "endpoint": Config.endpoint, # 例: oss-cn-beijing.aliyuncs.com
  114. "bucket_name": Config.bucket_name,
  115. "oss_prefix": Config.oss_prefix # OSS中存放截图的前缀(虚拟文件夹)
  116. }
  117. # 代码运行那时候的时间
  118. def app_current_time(self):
  119. return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  120. def app_start_time(self):
  121. """
  122. 获取app启动时间
  123. :return:
  124. """
  125. return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  126. def stop_app(self):
  127. self.d.app_stop(self.package_name)
  128. time.sleep(5)
  129. def start_app(self):
  130. self.d.app_start(self.package_name)
  131. time.sleep(5)
  132. def restart_app(self):
  133. """
  134. 重启app
  135. :return:
  136. """
  137. self.stop_app()
  138. self.start_app()
  139. @staticmethod
  140. def get_sleep_time():
  141. return random.randint(1, 3)
  142. # return random.randint(5, 8)
  143. @staticmethod
  144. def get_current_date():
  145. return datetime.datetime.now().strftime('%Y/%m/%d')
  146. @staticmethod
  147. def get_city_info():
  148. """
  149. 获取所有的省市数据
  150. :return:
  151. """
  152. file_path = '../kailin_city.json'
  153. with open(file_path, 'r', encoding='utf-8') as f:
  154. data = json.load(f)
  155. province = {province_one["id"]: province_one for province_one in data['province']}
  156. city2province = dict()
  157. city = data['city']
  158. for city_one in city:
  159. name = city_one['name']
  160. pid = city_one['pid']
  161. if len(str(pid)) > 2:
  162. pid = int(re.match(r'^\d{2}', str(pid)).group())
  163. city2province[name] = province[pid]['name']
  164. return city2province
  165. def remove_watermark(self, img_path):
  166. """
  167. 图片去水印(将水印部分变成白色背景)并将数据转化为二进制数据
  168. :param img_path: 图片路径
  169. :return: 二进制图片数据
  170. """
  171. img = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), -1)
  172. endswith = os.path.splitext(img_path)[1]
  173. new = np.clip(1.4057577998008846 * img - 38.33089999653017, 0, 255).astype(np.uint8)
  174. _, img_binary = cv2.imencode(endswith, new)
  175. return img_binary
  176. def human_slide(self, start_x, start_y, end_x, end_y):
  177. """模拟人类滑动轨迹"""
  178. # 生成带加速度的轨迹
  179. points = []
  180. total_steps = 50
  181. distance_x = end_x - start_x
  182. distance_y = end_y - start_y
  183. previous_x = start_x # 用于记录上一个 x 坐标值
  184. for i in range(total_steps):
  185. # 非线性进度(慢-快-慢)
  186. ratio = (i / total_steps)
  187. if ratio < 0.3:
  188. progress = 0.5 * (ratio / 0.3) ** 2
  189. elif ratio < 0.7:
  190. progress = 0.5 + (ratio - 0.3) * 1.25
  191. else:
  192. progress = 0.9 + 0.5 * ((ratio - 0.7) / 0.3) ** 0.5
  193. # 添加随机抖动
  194. # offset_x = np.random.randint(-2, 3)
  195. # offset_y = np.random.randint(-2, 3)
  196. offset_x = np.random.randint(-1, 1) # 控制抖动范围
  197. offset_y = np.random.randint(-1, 1)
  198. x = start_x + distance_x * min(progress, 0.99) + offset_x
  199. y = start_y + distance_y * min(progress, 0.99) + offset_y
  200. # 确保 x 坐标单调递增
  201. if x < previous_x and x < end_x:
  202. x = previous_x + 1
  203. if x > end_x:
  204. x = end_x
  205. previous_x = x
  206. points.append((x, y))
  207. # 变速延迟(移动越快延迟越短)
  208. delay = 0.002 + 0.01 * (1 - abs(0.5 - ratio))
  209. time.sleep(delay)
  210. print(f"points: {points}")
  211. self.loggerPdd.info(f"points: {points}")
  212. # 执行滑动轨迹
  213. # self.d.touch.down(points[0][0], points[0][1])
  214. for point in points[1:]:
  215. self.d.touch.move(point[0], point[1])
  216. self.d.touch.up(points[-1][0], points[-1][1])
  217. # print(f"points: {points}")
  218. # self.loggerPdd.info(f"points: {points}")
  219. # self.d.swipe_points(points, duration=0.05)
  220. def get_shop_name(self):
  221. """
  222. 获取店铺名
  223. :return:
  224. """
  225. try:
  226. xpath = '//*[@text="进店"]/preceding-sibling::android.view.ViewGroup/android.widget.LinearLayout/android.widget.TextView'
  227. if self.d.xpath(xpath).exists:
  228. shop_name = self.d.xpath(xpath).text
  229. self.loggerPdd.info(f'1-获取到店铺名:{shop_name}')
  230. else:
  231. # 进入店铺新页面
  232. shop_btn_xpath = '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]'
  233. if self.d.xpath(shop_btn_xpath).exists:
  234. self.d.xpath(shop_btn_xpath).click()
  235. time.sleep(1)
  236. # self.d.xpath('//*[@text="店铺"]').click()
  237. xpath_shop_name = '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.support.v7.widget.RecyclerView[1]/android.widget.RelativeLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.TextView[1]'
  238. if self.d.xpath(xpath_shop_name).exists:
  239. shop_name = self.d.xpath(xpath_shop_name).text
  240. self.loggerPdd.info(f'2-获取到店铺名:{shop_name}')
  241. else:
  242. shop_name = ''
  243. self.loggerPdd.info(f'3-获取到店铺名:{shop_name}')
  244. self.swipe_back(1) #
  245. else:
  246. shop_name = ''
  247. self.loggerPdd.info('4-因为shop_btn_xpath不存在,获取到店铺名为空')
  248. # time.sleep(10000)
  249. # 进入店铺新页面 测试代码
  250. # self.d.xpath('//*[@text="店铺"]').click()
  251. # time.sleep(1)
  252. # content_frame = self.d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]').exists
  253. # print(content_frame)
  254. # ViewGroup3 = self.d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]').exists
  255. # print(ViewGroup3)
  256. # LinearLayout = self.d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]').exists
  257. # print(LinearLayout)
  258. # RelativeLayout = self.d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]').exists
  259. # print(RelativeLayout)
  260. # LinearLayout2 = self.d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]').exists
  261. # print(LinearLayout2)
  262. # RecyclerView = self.d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.support.v7.widget.RecyclerView[1]').exists
  263. # print(RecyclerView)
  264. # xpath2 = '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.support.v7.widget.RecyclerView[1]/android.widget.RelativeLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.TextView[1]'
  265. # if self.d.xpath(xpath2).exists:
  266. # shop_name = self.d.xpath(xpath2).text
  267. # self.loggerPdd.info(f'2-获取到店铺名:{shop_name}')
  268. # else:
  269. # shop_name = ''
  270. # self.loggerPdd.info(f'3-获取到店铺名:{shop_name}')
  271. # self.swipe_back(1) #返回
  272. return shop_name
  273. except Exception as e:
  274. print(f'获取店铺名出错:{e}')
  275. self.loggerPdd.error(f'获取店铺名出错:{e}')
  276. return None
  277. def get_qualification_number(self):
  278. """
  279. 获取资质编号
  280. :return:
  281. """
  282. try:
  283. qualification_number_str = self.d.xpath(
  284. '//*[@resource-id="com.sankuai.meituan:id/mil_container"]/android.webkit.WebView[1]/android.webkit.WebView[1]/android.view.View[1]/android.view.View[1]/android.widget.TextView[2]').text
  285. qualification_number = qualification_number_str.strip('资质编号:').strip()
  286. return qualification_number
  287. except:
  288. return None
  289. def enter_detail(self):
  290. self.d.xpath('//*[@resource-id="com.sankuai.meituan:id/recycler"]/android.widget.FrameLayout[1]').click()
  291. time.sleep(self.get_sleep_time())
  292. def save_to_database(self, data):
  293. print(f'保存数据到数据库:{data}')
  294. # 连接数据库
  295. conn = get_mysql()
  296. # 创建游标对象
  297. cur = conn.cursor()
  298. # add_sql = "insert into delete_friend_table(delete_user_name,delete_user_id,delete_content,delete_time) value(%s,%s,%s,%s)"
  299. add_sql = f"""
  300. INSERT INTO {self.table_name}
  301. (product, min_price, manufacture_date, expiry_date, shop, business_license_company, province, city, manufacturer, specification, approval_number, product_link, scrape_date, scrape_province, availability, credit_code, platform, search_key, number)
  302. VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
  303. """
  304. # cur.execute(add_sql, (data['product'], data['min_price'], data['manufacture_date'], data['expiry_date'], data['shop'], data['business_license_company'],data['province'], data['city'], data['manufacturer'], data['specification'], data['approval_number'], data['product_link'], self.get_current_date(), data['scrape_province'], data['availability'], data['credit_code'], data['platform']))
  305. cur.execute(add_sql,
  306. (data['product'], data['min_price'], data['manufacture_date'], data['expiry_date'], data['shop'],
  307. data['business_license_company'], data['province'], data['city'], data['manufacturer'],
  308. data['specification'], data['approval_number'], data['product_link'], data['scrape_date'],
  309. data['scrape_province'], data['availability'], data['credit_code'], data['platform'],
  310. data['search_key'], data['number']))
  311. conn.commit() # 提交数据
  312. self.max_counts += 1
  313. print(f"存入数据库成功")
  314. def click_target_product_by_search_key(self, fuzzy_match=False, timeout=10):
  315. """
  316. 动态匹配self.search_key对应的商品并点击
  317. :param fuzzy_match: 是否模糊匹配(应对商品名带额外后缀/前缀的情况) 不模糊匹配
  318. :param timeout: 等待元素出现的超时时间(秒)
  319. :return: 点击是否成功(bool)
  320. """
  321. try:
  322. # 1. 定义定位条件(动态使用self.search_key)
  323. if fuzzy_match:
  324. # 模糊匹配:包含search_key即可(推荐,适配搜索结果商品名略有差异)
  325. locator = self.d(textContains=self.search_key)
  326. print(f"🔍 模糊匹配商品:包含「{self.search_key}」的元素")
  327. else:
  328. # 精确匹配:商品名与search_key完全一致
  329. locator = self.d(text=self.search_key)
  330. print(f"🔍 精确匹配商品:「{self.search_key}」")
  331. # 2. 等待元素出现(核心:避免元素未加载就点击)
  332. if locator.wait(timeout=timeout):
  333. print(f"✅ 找到匹配的商品,准备点击")
  334. # 执行点击(优先点击可点击的元素)
  335. locator.click()
  336. print(f"✅ 成功点击「{self.search_key}」对应的商品")
  337. # 点击后等待页面加载
  338. time.sleep(self.get_sleep_time())
  339. return True
  340. else:
  341. # print(f"❌ 超时未找到「{self.search_key}」对应的商品,尝试滑动刷新")
  342. # # 容错:向上滑动(加载更多)后重试
  343. # self.swipe_up()
  344. # 滑动后再等待5秒重试
  345. # if locator.wait(timeout=5):
  346. # locator.click()
  347. # print(f"✅ 滑动后找到并点击「{self.search_key}」对应的商品")
  348. # return True
  349. # else:
  350. print(f"❌ 滑动后仍未找到「{self.search_key}」对应的商品")
  351. return False
  352. except Exception as e:
  353. print(f"❌ 点击「{self.search_key}」对应商品时异常:{e}")
  354. return False
  355. def swipe_down(self):
  356. """
  357. 下滑(模拟真人操作,抗风控+设备适配+容错)
  358. 核心:起点在屏幕上方,终点在屏幕下方(和上滑相反)
  359. :return: None
  360. """
  361. try:
  362. # 1. 获取屏幕尺寸(兼容不同设备,给默认值避免获取失败)
  363. screen_width = self.d.info.get('displayWidth', 1080) # 默认1080px宽度
  364. screen_height = self.d.info.get('displayHeight', 2400) # 默认2400px高度
  365. # 2. 随机滑动时长(0.1~0.3秒,避免固定值被风控,且不设0秒)
  366. duration_rate = random.uniform(0.1, 0.3)
  367. # 3. 计算滑动坐标(用屏幕比例,适配所有设备)
  368. start_x = screen_width // 2 # 水平居中(和上滑一致,符合真人操作习惯)
  369. start_y = screen_height * 0.2 # 起点:屏幕20%高度(上方偏下)
  370. end_y = screen_height * 0.8 # 终点:屏幕80%高度(下方偏上)
  371. # 强制确保起点y < 终点y(必为向下滑,避免逻辑错误)
  372. start_y, end_y = min(start_y, end_y - 10), max(end_y, start_y + 10)
  373. # 4. 核心向下滑动操作
  374. self.d.swipe(start_x, start_y, start_x, end_y, duration=duration_rate)
  375. # 滑动后全局等待(确保页面加载,避免元素定位失败)
  376. time.sleep(self.get_sleep_time())
  377. except Exception as e:
  378. # 异常捕获:避免设备断开/滑动失败导致程序崩溃
  379. print(f"向下滑动失败:{e}")
  380. # 兜底方案:用固定坐标重试(适配主流1080x2400设备)
  381. self.d.swipe(540, 480, 540, 1920, duration=0.2)
  382. time.sleep(self.get_sleep_time())
  383. def swipe_up(self):
  384. """
  385. 上滑
  386. :return:
  387. """
  388. screen_width = self.d.info['displayWidth']
  389. screen_height = self.d.info['displayHeight']
  390. duration_rate = random.uniform(0, 0.3)
  391. self.d.swipe(screen_width // 2, screen_height - 100, screen_width // 2, 100, duration=duration_rate)
  392. no = random.uniform(0, 1)
  393. if no > 0.85:
  394. # 有的时候卡着 再稍微往上滑一点点
  395. self.d.swipe_ext("up", 0.1)
  396. time.sleep(self.get_sleep_time())
  397. def swipe_back(self, no):
  398. """
  399. 返回
  400. :param no: 回退次数
  401. :return:
  402. """
  403. if not self.distinct_target():
  404. for idx in range(no):
  405. self.d.press('back')
  406. time.sleep(self.get_sleep_time())
  407. def drug_price(self):
  408. """
  409. 获取药品价格
  410. :return:
  411. """
  412. try:
  413. xpath = '//*[@text="¥"]/following-sibling::android.widget.TextView[1]'
  414. price_str = self.d.xpath(xpath).text
  415. price = float(re.search(r'[\d\.]+', price_str).group())
  416. print(f'获取到价格:{price}')
  417. return float(price)
  418. except Exception as e:
  419. print(f'提取价格出错-->{e}')
  420. return None
  421. def drug_price_ex(self):
  422. price_str = '' # 价格初始化
  423. ext = '' # 初始化已选择的信息
  424. price = ''
  425. button_xpath_1 = '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.view.ViewGroup[last()]'
  426. button_xpath_2 = '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.view.ViewGroup[last()]'
  427. # 调试
  428. # test_button = self.d.xpath(button_xpath_1).exists
  429. # print(test_button)
  430. # test_button_2 = self.d.xpath(button_xpath_2).exists
  431. # print(test_button_2)
  432. # time.sleep(1000)
  433. # if self.d.xpath('//*[@text="发起拼单"]').exists:
  434. # self.d.xpath('//*[@text="发起拼单"]').click()
  435. # elif self.d.xpath('//*[@text="去复诊开药"]').exists:
  436. # self.d.xpath('//*[@text="去复诊开药"]').click()
  437. if self.d.xpath(button_xpath_1).exists:
  438. self.d.xpath(button_xpath_1).click()
  439. elif self.d.xpath(button_xpath_2).exists:
  440. self.d.xpath(button_xpath_2).click()
  441. else:
  442. print("button1 and button_2 all not exist")
  443. return price, ext
  444. # 获取是已选择还是请选择
  445. # select_xpath = '//*[@resource-id="android:id/content"]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.TextView[2]'
  446. select_xpath_1 = '//*[@resource-id="android:id/content"]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.TextView[last()]'
  447. select_xpath_2 = '//*[@resource-id="android:id/content"]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.TextView[last()]'
  448. select_xpath_3 = '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.view.ViewGroup[2]/android.widget.LinearLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.view.ViewGroup[1]/android.widget.TextView[last()]'
  449. select_xpath_3_2 = '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.view.ViewGroup[2]/android.widget.LinearLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.view.ViewGroup[1]/android.widget.TextView[last()-1]'
  450. # select_xpath1 = self.d.xpath(select_xpath_1).exists
  451. # print(select_xpath1)
  452. # select_xpath2 = self.d.xpath(select_xpath_2).exists
  453. # print(select_xpath2)
  454. # select_xpath3 = self.d.xpath(select_xpath_3).exists
  455. # print(select_xpath3)
  456. # time.sleep(1000)
  457. price_xpath_1 = '//*[@resource-id="android:id/content"]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.TextView[1]'
  458. price_xpath_2 = '//*[@resource-id="android:id/content"]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.TextView[1]'
  459. price_xpath_3 = '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.view.ViewGroup[2]/android.widget.LinearLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.view.ViewGroup[1]//android.widget.TextView[1]'
  460. if self.d.xpath(select_xpath_1).exists:
  461. text1 = self.d.xpath(select_xpath_1).text
  462. print(f"select_xpath_1--text1={text1}")
  463. if '已选' in text1:
  464. if self.d.xpath(price_xpath_1).exists:
  465. price_str = self.d.xpath(price_xpath_1).text
  466. print(f"select_xpath_1--price_str-1={price_str}")
  467. else:
  468. print("select_xpath_1--price_xpath_1-1 not exist")
  469. ext = text1
  470. elif '请选择' in text1:
  471. # 需要再下面点击选择
  472. scroll_xpath_1 = '//*[@resource-id="android:id/content"]//android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.support.v7.widget.RecyclerView[1]/android.widget.LinearLayout[last()]/android.view.ViewGroup[1]/android.view.ViewGroup[last()]'
  473. scroll_xpath_2 = ''
  474. if self.d.xpath(scroll_xpath_1).exists:
  475. self.d.xpath(scroll_xpath_1).click()
  476. time.sleep(2) # 延时2秒钟,选择了之后价格会刷新
  477. if self.d.xpath(select_xpath_1).exists:
  478. text2 = self.d.xpath(select_xpath_1).text
  479. if '已选' in text2:
  480. print(f"select_xpath_1--已选择2:text2={text2}")
  481. if self.d.xpath(price_xpath_1).exists:
  482. price_str = self.d.xpath(price_xpath_1).text
  483. print(f"select_xpath_1--price_str-2={price_str}")
  484. else:
  485. print("select_xpath_1--price_xpath_1-2 not exist")
  486. ext = text2
  487. else:
  488. print("select_xpath_1--scroll_xpath_1 not exist")
  489. elif self.d.xpath(select_xpath_2).exists:
  490. text1 = self.d.xpath(select_xpath_2).text
  491. print(f"xpath2--text1={text1}")
  492. if '已选' in text1:
  493. ext = text1
  494. if self.d.xpath(price_xpath_2).exists:
  495. price_str = self.d.xpath(price_xpath_2).text
  496. print(f"select_xpath_2--price_str-2={price_str}")
  497. else:
  498. print("select_xpath_2--price_xpath_2-1 not exist")
  499. elif '请选择' in text1:
  500. print('come in here')
  501. # 需要再下面点击选择
  502. scroll_xpath_1 = '//*[@resource-id="android:id/content"]//android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.support.v7.widget.RecyclerView[1]/android.widget.LinearLayout[last()]/android.view.ViewGroup[1]/android.view.ViewGroup[1]'
  503. if self.d.xpath(scroll_xpath_1).exists:
  504. print("scroll_xpath_1 exists")
  505. self.d.xpath(scroll_xpath_1).click()
  506. time.sleep(2) # 延时2秒钟,选择了之后价格可能会刷新
  507. if self.d.xpath(select_xpath_2).exists:
  508. text2 = self.d.xpath(select_xpath_2).text
  509. if '已选' in text2:
  510. ext = text2
  511. print(f"select_xpath_2--已选择2:text2={text2}")
  512. if self.d.xpath(price_xpath_2).exists:
  513. price_str = self.d.xpath(price_xpath_2).text
  514. print(f"select_xpath_2--price_str-2={price_str}")
  515. else:
  516. print("select_xpath_2--price_xpath_2-2 not exist")
  517. else:
  518. print("scroll_xpath_1 not exists")
  519. else:
  520. print("not exist 请选择 or 已选")
  521. elif self.d.xpath(select_xpath_3).exists:
  522. text1 = self.d.xpath(select_xpath_3).text
  523. print(f"xpath3--text1-1={text1}")
  524. if ('请选择' not in text1) and ('已选' not in text1):
  525. text1 = self.d.xpath(select_xpath_3_2).text
  526. print(f"xpath3--text1-2={text1}")
  527. if '已选' in text1:
  528. ext = text1
  529. if self.d.xpath(price_xpath_3).exists:
  530. price_str = self.d.xpath(price_xpath_3).text
  531. print(f"select_xpath_3--price_str-3-3-1={price_str}")
  532. else:
  533. print("select_xpath_3--price_xpath_3-3-1 not exist")
  534. elif '请选择' in text1:
  535. print('come in here')
  536. # 需要再下面点击选择
  537. scroll_xpath_1 = '//*[@resource-id="android:id/content"]//android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.support.v7.widget.RecyclerView[1]/android.widget.LinearLayout[last()]/android.view.ViewGroup[1]/android.view.ViewGroup[1]'
  538. recycler_view_xpath = '//*[@resource-id="android:id/content"]//android.support.v7.widget.RecyclerView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[last()]/android.view.ViewGroup[1]/android.view.ViewGroup[1]'
  539. if self.d.xpath(scroll_xpath_1).exists:
  540. print("scroll_xpath_1 exists")
  541. self.d.xpath(scroll_xpath_1).click()
  542. time.sleep(2) # 延时2秒钟,选择了之后价格可能会刷新
  543. if self.d.xpath(select_xpath_3).exists:
  544. text2 = self.d.xpath(select_xpath_3).text
  545. if '已选' in text2:
  546. ext = text2
  547. print(f"select_xpath_3--已选择2:text2={text2}")
  548. if self.d.xpath(price_xpath_3).exists:
  549. price_str = self.d.xpath(price_xpath_3).text
  550. print(f"select_xpath_3--price_str-3-2={price_str}")
  551. else:
  552. print("select_xpath_3--price_xpath_3-3-2 not exist")
  553. elif self.d.xpath(recycler_view_xpath).exists:
  554. self.d.xpath(recycler_view_xpath).click()
  555. time.sleep(2) # 延时2秒钟,选择了之后价格可能会刷新
  556. if self.d.xpath(select_xpath_3).exists:
  557. text2 = self.d.xpath(select_xpath_3).text
  558. if '已选' in text2:
  559. ext = text2
  560. print(f"select_xpath_3--已选择2:text2={text2}")
  561. if self.d.xpath(price_xpath_3).exists:
  562. price_str = self.d.xpath(price_xpath_3).text
  563. print(f"select_xpath_3--price_str-3-3={price_str}")
  564. else:
  565. print("select_xpath_3--price_xpath_3-3-3 not exist")
  566. else:
  567. print("scroll_xpath_1 not exists")
  568. else:
  569. print(f"xpath3--text1-不包含请选择和已选择")
  570. else:
  571. print("select_xpath_1 and select_xpath_2 and select_xpath_3 all not exist")
  572. if price_str:
  573. # price = float(re.search('[\d\.]+', price_str).group())
  574. match = re.search(r'¥([\d\.]+)', price_str)
  575. if match:
  576. price = float(match.group(1))
  577. else:
  578. price = ''
  579. # price = float(re.search(r'¥([\d\.]+)', price_str).group(1))
  580. print(f'获取到价格:{price}')
  581. print(f"ext={ext}")
  582. self.swipe_back(1) #
  583. # time.sleep(1000)
  584. return price, ext
  585. def restart_uiautomator_services(self, device_id):
  586. """
  587. 重启atx的uiautomator 服务
  588. :param device_id:
  589. :return:
  590. """
  591. stop_uiautomator_services = f'adb -s {device_id} shell /data/local/tmp/atx-agent server -d --stop'
  592. start_uiautomator_services = f'adb -s {device_id} shell /data/local/tmp/atx-agent server -d'
  593. # result = subprocess.run(stop_uiautomator_services, capture_output=True, text=True, shell=True)
  594. # print(result.stdout)
  595. subprocess.run(stop_uiautomator_services, capture_output=True, text=True, shell=True)
  596. time.sleep(self.get_sleep_time())
  597. subprocess.run(start_uiautomator_services, capture_output=True, text=True, shell=True)
  598. time.sleep(self.get_sleep_time())
  599. def connect_devices(self, device_id):
  600. """
  601. 连接设备
  602. :return:
  603. """
  604. try:
  605. self.d = u2.connect_usb(device_id)
  606. # 设置隐形等待时间
  607. # self.d.implicitly_wait(5)
  608. self.restart_uiautomator_services(device_id)
  609. print(f'[{self.program_start_time}]连接到设备:{device_id}')
  610. except Exception as e:
  611. print(f'{device_id} 连接错误: {e}')
  612. raise Exception(e)
  613. def get_ocr_res(self, img):
  614. try:
  615. image = self.remove_watermark(img)
  616. # image_file = open(img,'wb')
  617. # image_file.write(image)
  618. # res_image = self.client.basicAccurate(image) # 高精度
  619. res_image = self.client.basicGeneral(image)
  620. # print(f'百度api返回结果:{res_image}')
  621. # print(res_image.get('words_result', ''))
  622. # new_dic = dict()
  623. data = res_image.get('words_result', '')
  624. print(f'百度api返回结果:{data}')
  625. # full_text = ';'.join(item['words'] for item in data)
  626. # address = ''
  627. # for item in data:
  628. # if '企业注册号' in item['words']:
  629. # print('come in 111')
  630. # reg_number = item['words'].split(':', 1)[1].strip()
  631. # elif '企业名称' in item['words']:
  632. # print('come in 222')
  633. # company_name = item['words'].split(':', 1)[1].strip()
  634. # elif '所:' in item['words']:
  635. # print('come in 333')
  636. # address = item['words'].split(':', 1)[1].strip()
  637. # # 输出结果
  638. # print("企业注册号:", reg_number)
  639. # print("企业名称:", company_name)
  640. # print("住所:", address)
  641. return data
  642. except:
  643. return None
  644. # def get_ocr_res(self, img):
  645. # try:
  646. # #img地址
  647. # print(f'开始识别图片:{img}')
  648. # request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/business_license"
  649. # # 二进制方式打开图片文件
  650. # f = open(img, 'rb')
  651. # img = base64.b64encode(f.read())
  652. # # img = self.remove_watermark(img)
  653. # # print(f'图片转base64成功:{img}')
  654. # params = {"image": img}
  655. # # access_token = get_access_token()
  656. # request_url = request_url + "?access_token=" + self.access_token
  657. # headers = {'content-type': 'application/x-www-form-urlencoded'}
  658. # response = requests.post(request_url, data=params, headers=headers)
  659. # print(f'请求百度api成功{response}')
  660. # if response:
  661. # res = response.json()
  662. # print(f'百度api返回结果{res}')
  663. # new_dic = dict()
  664. # for ite in res['words_result'].keys():
  665. # new_dic[ite] = res['words_result'][ite]['words']
  666. # print('资质数据信息', new_dic)
  667. # return new_dic
  668. # else:
  669. # return None
  670. # except:
  671. # return None
  672. def screenshot_the_business_license(self):
  673. screenshot_path = 'screenshot1.png'
  674. self.d.screenshot(screenshot_path)
  675. img = cv2.imread(screenshot_path)
  676. # 指定裁剪区域 (left, top, right, bottom)
  677. left = 0
  678. top = 480
  679. right = 720
  680. bottom = 1420
  681. cropped_img = img[top:bottom, left:right]
  682. cropped_screenshot_path = 'cropped_screenshot.png'
  683. cv2.imwrite(cropped_screenshot_path, cropped_img)
  684. def screenshot_the_shop_qualifications(self):
  685. screenshot_path = 'screenshot2.png'
  686. self.d.screenshot(screenshot_path)
  687. img = cv2.imread(screenshot_path)
  688. # 指定裁剪区域 (left, top, right, bottom)
  689. left = 0
  690. top = 480
  691. right = 720
  692. bottom = 1420
  693. def first_screenshot_the_verify(self):
  694. screenshot_verify_path = 'first_screenshot_verify.png'
  695. self.d.screenshot(screenshot_verify_path)
  696. img = cv2.imread(screenshot_verify_path)
  697. ocr_res = self.get_ocr_res('first_screenshot_verify.png')
  698. event = '' # 事件类型:滑块验证、计算结果输入
  699. if ocr_res:
  700. for item in ocr_res:
  701. if '拖动滑块完成' in item['words']:
  702. print("滑块验证")
  703. event = '滑块验证'
  704. break
  705. # 指定裁剪区域 (left, top, right, bottom)
  706. if event == '滑块验证':
  707. left = 118
  708. top = 478
  709. right = 602
  710. bottom = 722
  711. else:
  712. left = 118
  713. top = 478
  714. right = 602
  715. bottom = 722
  716. cropped_verify_img = img[top:bottom, left:right]
  717. cropped_verify_creenshot_path = 'first_cropped_verify_screenshot.png'
  718. cv2.imwrite(cropped_verify_creenshot_path, cropped_verify_img)
  719. return event
  720. def slide_second_screenshot_the_verify(self):
  721. screenshot_verify_path = 'slide_second_screenshot_verify.png'
  722. self.d.screenshot(screenshot_verify_path)
  723. img = cv2.imread(screenshot_verify_path)
  724. left = 118
  725. top = 478
  726. right = 602
  727. bottom = 722
  728. cropped_verify_img = img[top:bottom, left:right]
  729. cropped_verify_creenshot_path = 'second_slide_cropped_verify_screenshot.png'
  730. cv2.imwrite(cropped_verify_creenshot_path, cropped_verify_img)
  731. def second_screenshot_the_verify(self):
  732. screenshot_verify_path = 'second_screenshot_verify.png'
  733. self.d.screenshot(screenshot_verify_path)
  734. img = cv2.imread(screenshot_verify_path)
  735. ocr_res = self.get_ocr_res('second_screenshot_verify.png')
  736. print(f'second_ocr_res:{ocr_res}')
  737. result = ''
  738. if ocr_res:
  739. result = '验证成功'
  740. for item in ocr_res:
  741. if '验证成功' in item['words']:
  742. result = '验证成功'
  743. break
  744. elif '验证不成功' in item['words']:
  745. result = '验证不成功'
  746. break
  747. return result
  748. def screenshot_business_license(self, shop_name):
  749. screenshot_lincense_path = 'license_screenshot.png'
  750. self.d.screenshot(screenshot_lincense_path)
  751. img = cv2.imread(screenshot_lincense_path)
  752. # 裁剪
  753. left = 0
  754. top = 160
  755. right = 720
  756. bottom = 1000
  757. cropped_verify_img = img[top:bottom, left:right]
  758. cropped_screenshot_path = 'D:\\work\\dfwy_spider\\drug_data\\pdd\\screenshot\\' + shop_name + '.png'
  759. cv2.imwrite(cropped_screenshot_path, cropped_verify_img)
  760. return cropped_screenshot_path
  761. def drug_slide(self, distance):
  762. print(f"滑动的distance= {distance}")
  763. # 获取设备上所有窗口的层次结构
  764. dump = self.d.dump_hierarchy()
  765. print(f"drug_slide-111:{dump}")
  766. # 解析 JSON 数据
  767. root = ET.fromstring(dump)
  768. # dump_data = json.loads(dump)
  769. print("drug_slide-222")
  770. # 查找包含 meco.webkit.WebView 的元素
  771. webview_elements = root.findall(".//node[@class='meco.webkit.WebView']")
  772. print("drug_slide-333")
  773. if webview_elements:
  774. print("找到 WebView 元素:", webview_elements[0].attrib)
  775. # 获取WebView的bounds信息
  776. webview_bounds = webview_elements[0].attrib['bounds']
  777. print("WebView bounds:", webview_bounds)
  778. # 假设你需要操作的元素在WebView中的XPath为'//node[@class="meco.webkit.WebView"]'
  779. webview_element_xpath = '//node[@class="meco.webkit.WebView"]'
  780. # 获取WebView内部元素
  781. webview_inner_elements = self.d.xpath(webview_element_xpath)
  782. if webview_inner_elements:
  783. # 拖动元素300像素
  784. start_x = webview_inner_elements[0].info['bounds'][0]
  785. start_y = webview_inner_elements[0].info['bounds'][1]
  786. end_x = start_x + distance
  787. end_y = start_y
  788. self.d.swipe(start_x, start_y, end_x, end_y)
  789. print("拖动成功")
  790. else:
  791. print("未找到需要拖动的元素")
  792. else:
  793. print("未找到 WebView 元素")
  794. def get_title(self):
  795. try:
  796. print('开始提取标题')
  797. time.sleep(self.get_sleep_time())
  798. title_xpath = '//*[@resource-id="com.xunmeng.pinduoduo:id/tv_title"]'
  799. if self.d.xpath(title_xpath).exists:
  800. title = self.d.xpath(title_xpath).info['contentDescription'].strip()
  801. else:
  802. return None
  803. # title = self.d.xpath('//*[@resource-id="com.xunmeng.pinduoduo:id/tv_title"]').info['contentDescription'].strip()
  804. print(f'提取到标题:{title}')
  805. return title
  806. except Exception as e:
  807. print(f'获取标题出错:{e}')
  808. return None
  809. # 从里面匹配出药品名和规格
  810. # drugs_name
  811. # specifications
  812. # match = re.search(r'([^\d]+)([\d\D]+)', title)
  813. # match = re.search(r'(\[[^\]]+\])(.+?)(\d+.*)', title)
  814. # if match:
  815. # drugs_name = match.group(1).strip() + match.group(2).strip()
  816. # specifications = match.group(3).strip()
  817. # print("药品名:", drugs_name)
  818. # print("规格:", specifications)
  819. # print('完整药名:', drugs_name + specifications)
  820. # return drugs_name, specifications
  821. # else:
  822. # print("没有匹配到预期格式")
  823. def enter_shop(self):
  824. """
  825. 进店,方便提取资质环境
  826. :return:
  827. """
  828. # self.d.xpath('//*[@text="进店"]').click()
  829. self.d.xpath('//*[@text="店铺"]').click()
  830. time.sleep(self.get_sleep_time())
  831. def enter_shoper(self):
  832. """
  833. 进入商家
  834. :return:
  835. """
  836. self.d.xpath('//*[@text="商家"]').click()
  837. time.sleep(self.get_sleep_time())
  838. def scan_shoper_license(self):
  839. self.d.xpath('//*[@text="查看商家资质"]').click()
  840. time.sleep(self.get_sleep_time())
  841. def data_is_exists(self, data):
  842. # 1. 验证必要字段
  843. required_keys = ['search_key', 'min_price', 'shop', 'scrape_date', 'platform']
  844. if not all(key in data for key in required_keys):
  845. missing = [key for key in required_keys if key not in data]
  846. # logging.error(f"缺少必要字段: {', '.join(missing)}")
  847. print(f"缺少必要字段: {', '.join(missing)}")
  848. return None
  849. try:
  850. # 连接数据库
  851. conn = get_mysql()
  852. # 创建游标对象
  853. cur = conn.cursor()
  854. # query_sql = f"SELECT * FROM {self.table_name} WHERE product = '{data['product']}' AND min_price = '{data['min_price']}' AND shop = '{data['shop']}' AND scrape_date = '{data['scrape_date']}' AND platform = '{data['platform']}'"
  855. # cur.execute(query_sql)
  856. query_sql = """
  857. SELECT * FROM {}
  858. WHERE search_key = %s
  859. AND min_price = %s
  860. AND shop = %s
  861. AND scrape_date = %s
  862. AND platform = %s
  863. """.format(self.table_name)
  864. cur.execute(query_sql, (
  865. data['search_key'],
  866. data['min_price'],
  867. data['shop'],
  868. data['scrape_date'],
  869. data['platform']
  870. ))
  871. result = cur.fetchone()
  872. return bool(result) # 如果存在返回True,否则False
  873. except Exception as e:
  874. print(f"MySQL 错误: {str(e)}")
  875. # 验证店铺信息是否在数据库中已存在
  876. def shop_is_exists_database(self, shop):
  877. try:
  878. # 连接数据库
  879. conn = get_mysql()
  880. # 创建游标对象
  881. cur = conn.cursor()
  882. query_sql = """
  883. SELECT * FROM {}
  884. WHERE shop = %s
  885. """.format(self.shop_table_name)
  886. cur.execute(query_sql, (
  887. shop
  888. ))
  889. result = cur.fetchone()
  890. return bool(result) # 如果存在返回True,否则False
  891. except Exception as e:
  892. print(f"MySQL 错误: {str(e)}")
  893. def get_instructions_data(self):
  894. """
  895. 确定有详情页之后之后,提取所有的详情页数据
  896. :return:
  897. """
  898. # 下面的for循环已经有滑动的操作了,不要一进来就滑动。
  899. # self.d.swipe_ext("up", scale=0.5)
  900. for i in range(8):
  901. # if self.d(textStartsWith="查看全部").exists:
  902. if self.d.xpath('//*[@text="品牌"]').exists or self.d.xpath('//*[@text="药品通用名"]').exists:
  903. self.d.swipe_ext("up", scale=0.1)
  904. print('开始采集详情数据')
  905. break
  906. # screen_width = self.d.info['displayWidth']
  907. # screen_height = self.d.info['displayHeight']
  908. # self.d.swipe(screen_width // 2, screen_height - 400, screen_width // 2, 400, duration=0.2)
  909. self.d.swipe_ext("up", scale=0.5)
  910. time.sleep(self.get_sleep_time())
  911. # 点击查看全部
  912. if self.d.xpath('//*[@text="品牌"]').exists:
  913. self.d.xpath('//*[@text="品牌"]').click()
  914. else:
  915. self.d.xpath('//*[@text="药品通用名"]').click()
  916. time.sleep(self.get_sleep_time())
  917. attr = dict()
  918. # # 获取详情页信息
  919. xpath = '//*[starts-with(@text,"商品参数")]/parent::*/parent::*/following-sibling::*/*/*/android.view.ViewGroup//android.widget.TextView'
  920. ddd = self.d.xpath(xpath).all()
  921. for i in range(0, len(ddd), 2):
  922. group = ddd[i:i + 2]
  923. attr[group[0].text] = group[1].text
  924. # 截图获取未获取到的数据
  925. # if not all(i in ['有效期', '生产企业', '批准文号', '药品规格', '产品规格'] for i in attr.keys()):
  926. if not all(i in ['有效期', '生产企业', '批准文号', '药品规格'] for i in attr.keys()):
  927. self.d.swipe_ext("up", 0.4)
  928. time.sleep(self.get_sleep_time())
  929. xpath = '//*[starts-with(@text,"商品参数")]/parent::*/parent::*/following-sibling::*/*/*/android.view.ViewGroup//android.widget.TextView'
  930. ddd = self.d.xpath(xpath).all()
  931. for i in range(0, len(ddd), 2):
  932. group = ddd[i:i + 2]
  933. attr[group[0].text] = group[1].text
  934. print(f'当前说明书规格参数:{attr}')
  935. res_data = {
  936. # "有效期": attr.get('有效期',''),
  937. # "生产单位": attr['生产企业'],
  938. # "批准文号": attr['批准文号'],
  939. # "产品规格": attr.get('药品规格') if attr.get('药品规格', '') else attr.get('药品规格')
  940. "有效期": attr.get('有效期', ''),
  941. "生产单位": attr.get('生产企业', ''),
  942. "批准文号": attr.get('批准文号', ''),
  943. "产品规格": attr.get('药品规格', '')
  944. }
  945. print(f'当前规格参数字典数据:{res_data}')
  946. return res_data
  947. def has_instructions(self):
  948. """
  949. 是否有详情页
  950. :return:如果有详情页返回True,否则返回False
  951. """
  952. # 没有说明书的无法采集具体数据
  953. max_attempts = 12 # 最大尝试次数
  954. attempt = 0 # 当前尝试次数
  955. while attempt < max_attempts:
  956. time.sleep(0.5)
  957. xpath = '//*[@text="商品详情"]'
  958. is_has_instructions = self.d.xpath(xpath).exists
  959. if is_has_instructions:
  960. return True # 如果找到“商品详情”,则返回True
  961. self.d.swipe_ext("up", 0.3)
  962. attempt += 1
  963. return False # 如果尝试次数达到最大次数,则返回False
  964. # time.sleep(self.get_sleep_time())
  965. # xpath = '//*[@text="商品详情"]'
  966. # is_has_instructions = self.d.xpath(xpath).exists
  967. # return
  968. def has_shop_qualifications(self):
  969. max_attempts = 3 # 最大尝试次数
  970. attempt = 0 # 当前尝试次数
  971. while attempt < max_attempts:
  972. time.sleep(0.5)
  973. xpath = '//*[@text="查看全部"]'
  974. is_has_search_all = self.d.xpath(xpath).exists
  975. if is_has_search_all:
  976. elements = self.d.xpath(xpath).all()
  977. count = len(elements)
  978. print(f"页面上共有 {count} 个 '查看全部' 元素")
  979. if count >= 2:
  980. second_element = elements[1]
  981. bounds = second_element.bounds
  982. else:
  983. element = self.d.xpath(xpath).get()
  984. bounds = element.bounds
  985. print(f'bounds:{bounds}')
  986. # time.sleep(1000000)
  987. # 获取元素的坐标和尺寸
  988. x1, y1, x2, y2 = bounds # x1, y1 是左上角坐标,x2, y2 是右下角坐标
  989. element_x = (x1 + x2) / 2 # 元素的中心 x 坐标
  990. element_y = (y1 + y2) / 2 # 元素的中心 y 坐标
  991. if element_y > 500:
  992. self.d.swipe(element_x, element_y, element_x, 500, 1)
  993. # 画完之后再去一次坐标
  994. elements_ex = self.d.xpath(xpath).all()
  995. count_ex = len(elements_ex)
  996. print(f"第二次页面上共有 {count_ex} 个 '查看全部' 元素")
  997. if count_ex >= 2:
  998. second_element_ex = elements[1]
  999. bounds_ex = second_element_ex.bounds
  1000. else:
  1001. element_ex = self.d.xpath(xpath).get()
  1002. bounds_ex = element_ex.bounds
  1003. print(f'bounds_ex:{bounds_ex}')
  1004. x1, y1, x2, y2 = bounds_ex # x1, y1 是左上角坐标,x2, y2 是右下角坐标
  1005. element_x = (x1 + x2) / 2 # 元素的中心 x 坐标
  1006. element_y = (y1 + y2) / 2 # 元素的中心 y 坐标
  1007. time.sleep(self.get_sleep_time())
  1008. target_x = element_x
  1009. target_y = element_y + 80
  1010. print(f'目标坐标:{target_x}, {target_y}')
  1011. # 点击图片
  1012. self.d.click(target_x, target_y)
  1013. time.sleep(self.get_sleep_time())
  1014. # 获取图片内容
  1015. self.screenshot_the_shop_qualifications()
  1016. ocr_res = self.get_ocr_res('screenshot2.png')
  1017. print(f'ocr_res:{ocr_res}')
  1018. time.sleep(100000)
  1019. return True # 如果找到“商品详情”,则返回True
  1020. self.d.swipe_ext("up", 0.1)
  1021. attempt += 1
  1022. return False # 如果尝试次数达到最大次数,则返回False
  1023. def get_license_info_ex(self, shop_name):
  1024. # print('开始获取商家资质信息')
  1025. self.enter_shop() # 点击店铺
  1026. # 点击店铺图片
  1027. xpath_shop_image = '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.support.v7.widget.RecyclerView[1]/android.widget.RelativeLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.ImageView[1]'
  1028. if self.d.xpath(xpath_shop_image).exists:
  1029. self.d.xpath(xpath_shop_image).click()
  1030. time.sleep(self.get_sleep_time())
  1031. # 从弹窗页获取店铺资质的位置
  1032. for i in range(10):
  1033. if self.d.xpath('//*[@text="店铺资质"]').exists:
  1034. print('店铺资质存在1')
  1035. break
  1036. self.d.swipe_ext('up', 0.3)
  1037. time.sleep(1)
  1038. if self.d.xpath('//*[@text="店铺资质"]').exists:
  1039. print('店铺资质存在2')
  1040. break
  1041. if self.d.xpath('//*[@text="已上传"]').exists:
  1042. self.d.xpath('//*[@text="已上传"]').click()
  1043. else:
  1044. self.d.xpath('//*[@text="店铺资质"]').click()
  1045. time.sleep(self.get_sleep_time())
  1046. xpath_pop_window = '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/meco.webkit.WebView[1]'
  1047. # 等待验证弹窗出现
  1048. for i in range(10):
  1049. if self.d.xpath(xpath_pop_window).exists:
  1050. print(f'第{i}次安全验证弹窗存在')
  1051. break
  1052. else:
  1053. print(f'第{i}次安全验证弹窗不存在')
  1054. time.sleep(self.get_sleep_time())
  1055. time.sleep(10)
  1056. # 第一次截屏
  1057. event = self.first_screenshot_the_verify()
  1058. # 用ocr的方式识别当前是拖动还是点击
  1059. # ocr_res = self.get_ocr_res('screenshot_verify.png')
  1060. # event = ''
  1061. # if ocr_res:
  1062. # for item in ocr_res:
  1063. # if '拖动滑块完成' in item['words']:
  1064. # print("滑块验证")
  1065. # event = '滑块验证'
  1066. # break
  1067. # print("ocr_res end")
  1068. if event == '滑块验证':
  1069. # 需要点击》按钮不懂后截屏,获取
  1070. self.d.touch.down(110, 780)
  1071. time.sleep(0.5)
  1072. # 截屏
  1073. event = self.slide_second_screenshot_the_verify()
  1074. # result = slide_verify('first_cropped_verify_screenshot.png') second_slide_cropped_verify_screenshot
  1075. result = slide_verify('second_slide_cropped_verify_screenshot.png')
  1076. result = int(result)
  1077. print(f'滑动距离:{result}')
  1078. print('开始滑动')
  1079. # internel = 1000
  1080. # self.d.touch.move_to(110 + result, 780, duration=internel)
  1081. # self.d.touch.up(110 + result, 780)
  1082. self.human_slide(110, 780, 110 + result, 780)
  1083. print('滑动结束')
  1084. time.sleep(self.get_sleep_time())
  1085. # 滑完之后怎么判断是否验证成功?
  1086. second_resut = self.second_screenshot_the_verify()
  1087. if second_resut == '验证成功':
  1088. time.sleep(8)
  1089. cropped_screenshot_path = self.screenshot_business_license(shop_name)
  1090. ocr_res = self.get_ocr_res(cropped_screenshot_path)
  1091. print(f'ocr_res:{ocr_res}')
  1092. company_name = ''
  1093. reg_number = ''
  1094. address = ''
  1095. if ocr_res:
  1096. for item in ocr_res:
  1097. if '企业注册号' in item['words']:
  1098. # print('come in 111')
  1099. reg_number = item['words'].split(':', 1)[1].strip()
  1100. elif '企业名称' in item['words']:
  1101. # print('come in 222')
  1102. company_name = item['words'].split(':', 1)[1].strip()
  1103. elif '所:' in item['words']:
  1104. # print('come in 333')
  1105. address = item['words'].split(':', 1)[1].strip()
  1106. # 输出结果
  1107. print("企业注册号:", reg_number)
  1108. print("企业名称:", company_name)
  1109. print("住所:", address)
  1110. print("yanzhenghcenggong")
  1111. # 截取图片保存 第三次截屏,保存到本地
  1112. # 将图片传给第三方verify接口得到需要移动的距离
  1113. # result = slide_verify('cropped_verify_screenshot.png')
  1114. # print(f'滑动距离:{result}')
  1115. # self.drug_slide(340)
  1116. # print('开始滑动')
  1117. # self.d.swipe(120, 760, 460, 760, 0.3)
  1118. # print('滑动结束')
  1119. # time.sleep(1000000)
  1120. # 截图获取需要验证的内容
  1121. def get_license_info(self):
  1122. self.enter_shop()
  1123. self.enter_shoper()
  1124. self.scan_shoper_license()
  1125. # 获取资质编码
  1126. qualification_number = self.get_qualification_number()
  1127. if qualification_number:
  1128. table_license_info = self.get_table_license_info(qualification_number)
  1129. if table_license_info:
  1130. return {
  1131. '单位名称': table_license_info[0],
  1132. '地址': table_license_info[1],
  1133. '社会信用代码': table_license_info[2]
  1134. }
  1135. else:
  1136. # operate_no = random.randint(0, 1)
  1137. self.d.click(0.603, 0.27)
  1138. # if operate_no == 0:
  1139. # self.d.xpath('//*[@text="营业执照"]').click()
  1140. # else:
  1141. # self.d.click(0.603, 0.27)
  1142. time.sleep(self.get_sleep_time())
  1143. self.screenshot_the_business_license()
  1144. ocr_res = self.get_ocr_res('cropped_screenshot.png')
  1145. return ocr_res
  1146. # operate_no = random.randint(0, 1)
  1147. self.d.click(0.603, 0.27)
  1148. # if operate_no == 0:
  1149. # self.d.xpath('//*[@text="营业执照"]').click()
  1150. # else:
  1151. # self.d.click(0.603, 0.27)
  1152. time.sleep(self.get_sleep_time())
  1153. self.screenshot_the_business_license()
  1154. ocr_res = self.get_ocr_res('cropped_screenshot.png')
  1155. return ocr_res
  1156. def distinct_target(self):
  1157. result = False
  1158. is_position = self.d.xpath('//*[@content-desc="拍照搜索"]').exists
  1159. is_position2 = self.d.xpath('//*[@text="年货节大促"]').exists
  1160. is_position3 = self.d.xpath('//*[@text="筛选"]').exists
  1161. is_position4 = self.d.xpath('//*[@text="回头客常拼"]').exists
  1162. list_page_xpath = '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[2]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]//android.support.v7.widget.RecyclerView[1]'
  1163. is_position_new = self.d.xpath(list_page_xpath).exists
  1164. print(f'is_position_new={is_position_new}')
  1165. if is_position or is_position2 or is_position3 or is_position4 or is_position_new:
  1166. result = True
  1167. return result
  1168. def enter_target_page(self):
  1169. self.d.xpath(
  1170. '//*[@resource-id="android:id/content"]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]').click()
  1171. time.sleep(self.get_sleep_time())
  1172. self.d(className='android.widget.EditText').click()
  1173. time.sleep(self.get_sleep_time())
  1174. self.d.send_keys(self.search_key, clear=True)
  1175. time.sleep(self.get_sleep_time())
  1176. self.d.xpath('//*[@text="搜索"]').click()
  1177. time.sleep(self.get_sleep_time())
  1178. """暂不用该功能
  1179. def get_table_license_info(self, qualification_number):
  1180. try:
  1181. sql = f'select business_license_company,city,credit_code from mt_drug where credit_code = "{qualification_number}"'
  1182. self.mysql_client.cur.execute(sql)
  1183. res = self.mysql_client.cur.fetchone()
  1184. return res
  1185. except:
  1186. return None
  1187. """
  1188. def get_clipboard(self):
  1189. self.loggerPdd.info(f"Clipboard content:{self.d.clipboard}") # 打印调试信息
  1190. clipboard_content = self.d.clipboard
  1191. if clipboard_content is None:
  1192. return ''
  1193. return clipboard_content.strip()
  1194. def clear_clipboard(self):
  1195. self.d.set_clipboard("")
  1196. def get_product_link(self):
  1197. product_link = ''
  1198. print('开始获取商品链接')
  1199. content_frame = self.d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]').exists
  1200. print(content_frame)
  1201. relative_layout = self.d.xpath(
  1202. '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]').exists
  1203. print(relative_layout)
  1204. relative_layout2 = self.d.xpath(
  1205. '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]').exists
  1206. print(relative_layout2)
  1207. Frame_Layout = self.d.xpath(
  1208. '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[2]').exists
  1209. print(Frame_Layout)
  1210. ImageView = self.d.xpath(
  1211. '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[2]/android.view.View[1]').exists
  1212. print(ImageView)
  1213. ImageView2 = self.d.xpath(
  1214. '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[3]/android.view.View[1]').exists
  1215. print(ImageView2)
  1216. # time.sleep(10000)
  1217. '''
  1218. if self.d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[2]/android.view.View[1]').exists:
  1219. self.d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[2]/android.view.View[1]').click()
  1220. print('进入分享成功')
  1221. time.sleep(1)
  1222. #先清除剪切板的数据
  1223. # self.clear_clipboard()
  1224. #需要增加从右往左的滑动
  1225. # self.d.swipe_ext("left", 0.5)
  1226. print('开始滑动')
  1227. self.d.swipe(400, 1250, 100, 1250, 0.2)
  1228. time.sleep(0.2)
  1229. if self.d.xpath('//*[@text="复制链接"]').exists:
  1230. self.d.xpath('//*[@text="复制链接"]').click()
  1231. print('点击复制链接')
  1232. # self.d.xpath('//*[@text="复制链接"]').click_exists()
  1233. # self.d.xpath('//*[contains(@text="复")]').click_exists()
  1234. # time.sleep(1)
  1235. product_link = self.get_clipboard()
  1236. time.sleep(0.5)
  1237. print(f'商品链接:{product_link}')
  1238. elif self.d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[3]/android.view.View[1]').exists:
  1239. self.d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[3]/android.view.View[1]').click()
  1240. print('进入分享成功111')
  1241. time.sleep(1)
  1242. print('开始滑动')
  1243. self.d.swipe(400, 1250, 100, 1250, 0.2)
  1244. time.sleep(0.2)
  1245. if self.d.xpath('//*[@text="复制链接"]').exists:
  1246. self.d.xpath('//*[@text="复制链接"]').click()
  1247. print('点击复制链接')
  1248. product_link = self.get_clipboard()
  1249. time.sleep(0.5)
  1250. print(f'商品链接:{product_link}')
  1251. else:
  1252. print('进入分享失败')
  1253. time.sleep(10000)
  1254. '''
  1255. # 多种可能的“分享”按钮
  1256. dots_xpaths = [
  1257. # '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[2]/android.view.View[1]',
  1258. '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[last()]/android.view.View[1]',
  1259. # '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[2]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[2]/android.view.View[1]',
  1260. # '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[2]/android.widget.RelativeLayout[2]/android.widget.FrameLayout[3]/android.widget.ImageView[1]',
  1261. ]
  1262. max_retry = 5 # 最多尝试次数
  1263. for idx in range(1, max_retry + 1):
  1264. if product_link: # 已经拿到则退出
  1265. break
  1266. for xp in dots_xpaths:
  1267. if self.d.xpath(xp).exists:
  1268. # print(f'{idx}-进入分享点点点')
  1269. self.loggerPdd.info(f'{idx}-进入分享点点点')
  1270. self.d.xpath(xp).click()
  1271. time.sleep(1)
  1272. # self.d.xpath('//*[@text="分享商品"]').click_exists()
  1273. # time.sleep(0.2)
  1274. # print('开始滑动')
  1275. self.loggerPdd.info('开始滑动')
  1276. if (
  1277. self.device_id == '2e58510' or self.device_id == 'fcb3c749' or self.device_id == 'ea4e4eb8' or self.device_id == '95b2c764' or
  1278. self.device_id == '369dcf96' or self.device_id == 'ZDQWUSSWBEDI896T' or self.device_id == 'IRLZAAQCDMHYWKTS' or
  1279. self.device_id == 'U47HZDRG8XJBBURW' or self.device_id == 'WWRO9LTGG6KFGQCM' or self.device_id == 'fcb3c749' or
  1280. self.device_id == 'OVFETO8PCY45E6A6' or self.device_id == 'U8ONIJJJS4CELVD6'):
  1281. self.d.swipe(400, 1350, 100, 1350, 0.3)
  1282. elif (
  1283. self.device_id == 'KNNNEMNVWCJZQOLZ' or self.device_id == 'CMKFUSSG99ROR489' or self.device_id == '656DTOPRZDEALZ5X' or
  1284. self.device_id == 'UCQGF6CQFMU8WKHI' or self.device_id == '4TZDUGTOAIFMJVGU' or self.device_id == 'DEZXWKUC7DJBLVPJ' or
  1285. self.device_id == 'GQIRKB7LVOONM7VW'):
  1286. self.d.swipe(400, 1300, 100, 1300, 0.3)
  1287. elif self.device_id == 'e2899b34':
  1288. self.d.swipe(400, 1150, 100, 1150, 0.3)
  1289. else:
  1290. self.d.swipe(400, 1250, 100, 1250, 0.3)
  1291. # self.d.swipe(400, 1250, 100, 1250, 0.3)
  1292. # self.d.drag(300, 1280, 50, 1280, 0.3)
  1293. # self.d.swipe_ext('left', 0.3)
  1294. time.sleep(0.2)
  1295. self.d.xpath('//*[@text="复制链接"]').click_exists()
  1296. time.sleep(1)
  1297. product_link = self.get_clipboard()
  1298. time.sleep(0.5)
  1299. # print(f'{idx}-商品链接:{product_link}')
  1300. self.loggerPdd.info(f'{idx}-商品链接:{product_link}')
  1301. break # 找到并执行后跳出内层循环
  1302. # if self.d.xpath('//*[@text="复制链接"]').exists:
  1303. # self.d.xpath('//*[@text="复制链接"]').click()
  1304. # # print('点击复制链接')
  1305. # self.loggerPdd.info('点击复制链接')
  1306. # product_link = self.get_clipboard()
  1307. # time.sleep(0.5)
  1308. # # print(f'{idx}-商品链接:{product_link}')
  1309. # self.loggerPdd.info(f'{idx}-商品链接:{product_link}')
  1310. # break # 找到并执行后跳出内层循环
  1311. if not product_link and idx < max_retry:
  1312. time.sleep(0.5) # 最后一次不需要再等待
  1313. # time.sleep(100000)
  1314. return product_link
  1315. def integrate_data(self):
  1316. """
  1317. 整合数据
  1318. :return:
  1319. """
  1320. # 测试通过点击店铺获取店铺的名称:
  1321. # shop = self.get_shop_name()
  1322. # print(f'店铺名称:{shop}')
  1323. # time.sleep(100000)
  1324. # 测试点击店铺进入获取店铺资质
  1325. # license_info = self.get_license_info_ex('1234')#店铺名称
  1326. # time.sleep(100000)
  1327. # 首先判断是否存在:商品已售罄,推荐以下相似商品 的文本
  1328. # if self.d.xpath('//*[contains(@text, "商品已售罄,推荐以下相似商品")]'):
  1329. # self.loggerPdd.info(f'商品已售罄:{self.search_key}')
  1330. # self.swipe_back(1)
  1331. # return
  1332. # 获取价格和盒数备注
  1333. min_price, ext = self.drug_price_ex() # 最低价格和盒数备注
  1334. title_info = self.get_title() # 药品名字
  1335. if title_info:
  1336. if '999' in self.search_key:
  1337. temp_search_key = self.search_key.replace('999', '')
  1338. if self.search_key == '999强力枇杷露225ml':
  1339. temp_search_key = temp_search_key.replace('225ml', '')
  1340. elif self.search_key == '999糠酸莫米松凝胶15':
  1341. temp_search_key = temp_search_key.replace('15', '')
  1342. elif self.search_key == '999养胃舒颗粒10g*6':
  1343. temp_search_key = temp_search_key.replace('10g*6', '')
  1344. elif self.search_key == '999曲安奈德益康唑乳膏30g':
  1345. temp_search_key = temp_search_key.replace('30g', '')
  1346. elif self.search_key == '999抗病毒口服液10ml*6支':
  1347. temp_search_key = temp_search_key.replace('10ml*6支', '')
  1348. elif self.search_key == '999复方板蓝根颗粒15袋':
  1349. temp_search_key = temp_search_key.replace('15袋', '')
  1350. elif self.search_key == '999可调式生理性海水鼻腔喷雾50':
  1351. temp_search_key = temp_search_key.replace('50', '')
  1352. elif self.search_key == '999维生素E.C颗粒9袋':
  1353. temp_search_key = temp_search_key.replace('9袋', '')
  1354. elif self.search_key == '999复方氨酚烷胺胶囊6粒':
  1355. temp_search_key = temp_search_key.replace('6粒', '')
  1356. elif self.search_key == '999复方板蓝根颗粒15g*15袋':
  1357. temp_search_key = temp_search_key.replace('15g*15袋', '')
  1358. elif self.search_key == '999止泻利颗粒15g*8':
  1359. temp_search_key = temp_search_key.replace('15g*8', '')
  1360. elif self.search_key == '999三蛇胆川贝膏138':
  1361. temp_search_key = temp_search_key.replace('138', '')
  1362. elif self.search_key == '999强力枇杷露16袋':
  1363. temp_search_key = temp_search_key.replace('16袋', '')
  1364. elif self.search_key == '999复方苦参肠炎康片12片':
  1365. temp_search_key = temp_search_key.replace('12片', '')
  1366. elif self.search_key == '999必无忧盐酸特比萘芬乳膏15':
  1367. temp_search_key = temp_search_key.replace('必无忧', '')
  1368. temp_search_key = temp_search_key.replace('15', '')
  1369. elif self.search_key == '999速复康布洛芬缓释胶囊':
  1370. temp_search_key = temp_search_key.replace('速复康', '')
  1371. elif self.search_key == '999强力枇杷露120ml':
  1372. temp_search_key = temp_search_key.replace('120ml', '')
  1373. elif self.search_key == '999强力枇杷露150ml':
  1374. temp_search_key = temp_search_key.replace('150ml', '')
  1375. elif self.search_key == '999抗病毒口服液10ml*10':
  1376. temp_search_key = temp_search_key.replace('10ml*10', '')
  1377. elif self.search_key == '999抗病毒口服液10ml*12':
  1378. temp_search_key = temp_search_key.replace('10ml*12', '')
  1379. elif self.search_key == '999感冒清热颗粒6g*10':
  1380. temp_search_key = temp_search_key.replace('6g*10', '')
  1381. elif self.search_key == '999选平硝酸咪康唑乳膏20g':
  1382. temp_search_key = temp_search_key.replace('选平', '')
  1383. temp_search_key = temp_search_key.replace('20g', '')
  1384. elif self.search_key == '999糠酸莫米松乳膏10g':
  1385. temp_search_key = temp_search_key.replace('10g', '')
  1386. elif self.search_key == '999壮骨关节丸6g*20':
  1387. temp_search_key = temp_search_key.replace('6g*20', '')
  1388. elif self.search_key == '999正天丸6g*15':
  1389. temp_search_key = temp_search_key.replace('6g*15', '')
  1390. elif self.search_key == '999藿香正气合剂10ml*6':
  1391. temp_search_key = temp_search_key.replace('10ml*6', '')
  1392. elif self.search_key == '999藿香正气合剂10ml*10':
  1393. temp_search_key = temp_search_key.replace('10ml*10', '')
  1394. elif self.search_key == '999小儿止咳糖浆120':
  1395. temp_search_key = temp_search_key.replace('120', '')
  1396. elif self.search_key == '999小儿止咳糖浆225':
  1397. temp_search_key = temp_search_key.replace('225', '')
  1398. elif self.search_key == '999小儿感冒颗粒6g*10':
  1399. temp_search_key = temp_search_key.replace('6g*10', '')
  1400. elif self.search_key == '999小儿感冒颗粒6g*24':
  1401. temp_search_key = temp_search_key.replace('6g*24', '')
  1402. elif self.search_key == '999小儿氨酚黄那敏颗粒6g*10袋':
  1403. temp_search_key = temp_search_key.replace('6g*10袋', '')
  1404. elif self.search_key == '999小儿氨酚黄那敏颗粒6g*20袋':
  1405. temp_search_key = temp_search_key.replace('6g*20袋', '')
  1406. elif self.search_key == '999感冒灵颗粒10g*9袋':
  1407. temp_search_key = temp_search_key.replace('10g*9袋', '')
  1408. elif self.search_key == '999皮炎平复方醋酸地塞米松乳膏20':
  1409. temp_search_key = temp_search_key.replace('皮炎平', '')
  1410. temp_search_key = temp_search_key.replace('20', '')
  1411. elif self.search_key == '999糠酸莫米松凝胶10':
  1412. temp_search_key = temp_search_key.replace('10', '')
  1413. elif self.search_key == '999板蓝根颗粒10g*20':
  1414. temp_search_key = temp_search_key.replace('10g*20', '')
  1415. elif self.search_key == '999咽炎片0.26g*12片':
  1416. temp_search_key = temp_search_key.replace('0.26g*12片', '')
  1417. elif self.search_key == '999小儿咽扁颗粒8g*10袋':
  1418. temp_search_key = temp_search_key.replace('8g*10袋', '')
  1419. elif self.search_key == '999感冒清热颗粒12g*18':
  1420. temp_search_key = temp_search_key.replace('12g*18', '')
  1421. elif self.search_key == '999小柴胡颗粒10g*15':
  1422. temp_search_key = temp_search_key.replace('10g*15', '')
  1423. # print (f"temp_search_key={temp_search_key}")
  1424. if self.search_key == '999抗病毒口服液': # 如果标题不包含 999 或 抗病毒口服液 或 (10ml*12 和 10ml*18) 则退出
  1425. if '999' not in title_info or temp_search_key not in title_info:
  1426. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1427. self.swipe_back(1)
  1428. self.unrelated_data += 1
  1429. return
  1430. elif '10ml*12' not in title_info and '10ml*10' not in title_info:
  1431. print(f"当前商品名称:{title_info} 不包含10*12或10*10品规")
  1432. self.swipe_back(1)
  1433. self.unrelated_data += 1
  1434. return
  1435. elif self.search_key == '999抗病毒口服液10ml*6支': # 如果标题不包含 999 或 抗病毒口服液 或 (10ml*12 和 10ml*18) 则退出
  1436. if '999' not in title_info or temp_search_key not in title_info:
  1437. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1438. self.swipe_back(1)
  1439. self.unrelated_data += 1
  1440. return
  1441. elif '10ml*6' not in title_info:
  1442. print(f"当前商品名称:{title_info} 不包含10ml*6品规")
  1443. self.swipe_back(1)
  1444. self.unrelated_data += 1
  1445. return
  1446. elif self.search_key == '999曲安奈德益康唑乳膏30g':
  1447. if '999' not in title_info or temp_search_key not in title_info:
  1448. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1449. self.swipe_back(1)
  1450. self.unrelated_data += 1
  1451. return
  1452. elif '30' not in title_info:
  1453. print(f"当前商品名称:{title_info} 不包含30品规")
  1454. self.swipe_back(1)
  1455. self.unrelated_data += 1
  1456. return
  1457. elif self.search_key == '999复方感冒灵颗粒':
  1458. if '999' not in title_info or temp_search_key not in title_info:
  1459. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1460. self.swipe_back(1)
  1461. self.unrelated_data += 1
  1462. return
  1463. elif '14g*15' not in title_info:
  1464. print(f"当前商品名称:{title_info} 不包含14g*15 和 14g*9品规")
  1465. self.swipe_back(1)
  1466. self.unrelated_data += 1
  1467. return
  1468. elif self.search_key == '999养胃舒颗粒10g*6':
  1469. if '999' not in title_info or temp_search_key not in title_info:
  1470. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1471. self.swipe_back(1)
  1472. self.unrelated_data += 1
  1473. return
  1474. elif '10g*6' not in title_info:
  1475. print(f"当前商品名称:{title_info} 不包含10g*6品规")
  1476. self.swipe_back(1)
  1477. self.unrelated_data += 1
  1478. return
  1479. elif self.search_key == '999糠酸莫米松凝胶15':
  1480. if '999' not in title_info or temp_search_key not in title_info:
  1481. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1482. self.swipe_back(1)
  1483. self.unrelated_data += 1
  1484. return
  1485. elif '15' not in title_info:
  1486. print(f"当前商品名称:{title_info} 不包含15品规")
  1487. self.swipe_back(1)
  1488. self.unrelated_data += 1
  1489. return
  1490. elif self.search_key == '999强力枇杷露225ml':
  1491. if '999' not in title_info or temp_search_key not in title_info:
  1492. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1493. self.swipe_back(1)
  1494. self.unrelated_data += 1
  1495. return
  1496. elif '225' not in title_info:
  1497. print(f"当前商品名称:{title_info} 不包含225品规")
  1498. self.swipe_back(1)
  1499. self.unrelated_data += 1
  1500. return
  1501. elif self.search_key == '999强力枇杷露120ml':
  1502. if '999' not in title_info or temp_search_key not in title_info:
  1503. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1504. self.swipe_back(1)
  1505. self.unrelated_data += 1
  1506. return
  1507. elif '120' not in title_info:
  1508. print(f"当前商品名称:{title_info} 不包含120品规")
  1509. self.swipe_back(1)
  1510. self.unrelated_data += 1
  1511. return
  1512. elif self.search_key == '999强力枇杷露150ml':
  1513. if '999' not in title_info or temp_search_key not in title_info:
  1514. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1515. self.swipe_back(1)
  1516. self.unrelated_data += 1
  1517. return
  1518. elif '150' not in title_info:
  1519. print(f"当前商品名称:{title_info} 不包含150品规")
  1520. self.swipe_back(1)
  1521. self.unrelated_data += 1
  1522. return
  1523. elif self.search_key == '999抗病毒口服液10ml*10':
  1524. if '999' not in title_info or temp_search_key not in title_info:
  1525. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1526. self.swipe_back(1)
  1527. self.unrelated_data += 1
  1528. return
  1529. elif '10ml*10' not in title_info:
  1530. print(f"当前商品名称:{title_info} 不包含10ml*10品规")
  1531. self.swipe_back(1)
  1532. self.unrelated_data += 1
  1533. return
  1534. elif self.search_key == '999抗病毒口服液10ml*12':
  1535. if '999' not in title_info or temp_search_key not in title_info:
  1536. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1537. self.swipe_back(1)
  1538. self.unrelated_data += 1
  1539. return
  1540. elif '10ml*12' not in title_info:
  1541. print(f"当前商品名称:{title_info} 不包含10ml*12品规")
  1542. self.swipe_back(1)
  1543. self.unrelated_data += 1
  1544. return
  1545. elif self.search_key == '999复方板蓝根颗粒15袋':
  1546. if '999' not in title_info or temp_search_key not in title_info:
  1547. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1548. self.swipe_back(1)
  1549. self.unrelated_data += 1
  1550. return
  1551. elif '15袋' not in title_info:
  1552. print(f"当前商品名称:{title_info} 不包含15袋品规")
  1553. self.swipe_back(1)
  1554. self.unrelated_data += 1
  1555. return
  1556. elif self.search_key == '999可调式生理性海水鼻腔喷雾50':
  1557. if '999' not in title_info or temp_search_key not in title_info:
  1558. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1559. self.swipe_back(1)
  1560. self.unrelated_data += 1
  1561. return
  1562. elif self.search_key == '999维生素E.C颗粒9袋':
  1563. if '999' not in title_info or temp_search_key not in title_info:
  1564. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1565. self.swipe_back(1)
  1566. self.unrelated_data += 1
  1567. return
  1568. elif self.search_key == '999复方氨酚烷胺胶囊6粒':
  1569. if '999' not in title_info or temp_search_key not in title_info:
  1570. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1571. self.swipe_back(1)
  1572. self.unrelated_data += 1
  1573. return
  1574. elif '6粒' not in title_info:
  1575. print(f"当前商品名称:{title_info} 不包含6粒品规")
  1576. self.swipe_back(1)
  1577. self.unrelated_data += 1
  1578. return
  1579. elif self.search_key == '999复方板蓝根颗粒15g*15袋':
  1580. if '999' not in title_info or temp_search_key not in title_info:
  1581. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1582. self.swipe_back(1)
  1583. self.unrelated_data += 1
  1584. return
  1585. elif '15g*15' not in title_info:
  1586. print(f"当前商品名称:{title_info} 不包含15g*15品规")
  1587. self.swipe_back(1)
  1588. self.unrelated_data += 1
  1589. return
  1590. elif self.search_key == '999止泻利颗粒15g*8':
  1591. if '999' not in title_info or temp_search_key not in title_info:
  1592. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1593. self.swipe_back(1)
  1594. self.unrelated_data += 1
  1595. return
  1596. elif '15g*8' not in title_info:
  1597. print(f"当前商品名称:{title_info} 不包含15g*8品规")
  1598. self.swipe_back(1)
  1599. self.unrelated_data += 1
  1600. return
  1601. elif self.search_key == '999三蛇胆川贝膏138':
  1602. if '999' not in title_info or temp_search_key not in title_info:
  1603. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1604. self.swipe_back(1)
  1605. self.unrelated_data += 1
  1606. return
  1607. elif '138' not in title_info:
  1608. print(f"当前商品名称:{title_info} 不包含138品规")
  1609. self.swipe_back(1)
  1610. self.unrelated_data += 1
  1611. return
  1612. elif self.search_key == '999强力枇杷露16袋':
  1613. if '999' not in title_info or temp_search_key not in title_info:
  1614. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1615. self.swipe_back(1)
  1616. self.unrelated_data += 1
  1617. return
  1618. elif '16袋' not in title_info:
  1619. print(f"当前商品名称:{title_info} 不包含16袋品规")
  1620. self.swipe_back(1)
  1621. self.unrelated_data += 1
  1622. return
  1623. elif self.search_key == '999复方苦参肠炎康片12片':
  1624. if '999' not in title_info or temp_search_key not in title_info:
  1625. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1626. self.swipe_back(1)
  1627. self.unrelated_data += 1
  1628. return
  1629. elif '12片' not in title_info:
  1630. print(f"当前商品名称:{title_info} 不包含12片品规")
  1631. self.swipe_back(1)
  1632. self.unrelated_data += 1
  1633. return
  1634. elif self.search_key == '999必无忧盐酸特比萘芬乳膏15':
  1635. if temp_search_key not in title_info:
  1636. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1637. self.swipe_back(1)
  1638. self.unrelated_data += 1
  1639. return
  1640. elif ('999' not in title_info) and ('必无忧' not in title_info):
  1641. print(f"当前商品名称:{title_info} 不包含关键字:999或 必无忧")
  1642. self.swipe_back(1)
  1643. self.unrelated_data += 1
  1644. return
  1645. elif '15' not in title_info:
  1646. print(f"当前商品名称:{title_info} 不包含15品规")
  1647. self.swipe_back(1)
  1648. self.unrelated_data += 1
  1649. return
  1650. elif self.search_key == '999速复康布洛芬缓释胶囊':
  1651. if temp_search_key not in title_info:
  1652. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1653. self.swipe_back(1)
  1654. self.unrelated_data += 1
  1655. return
  1656. elif ('999' not in title_info) and ('速复康' not in title_info):
  1657. print(f"当前商品名称:{title_info} 不包含关键字:999或 速复康")
  1658. self.swipe_back(1)
  1659. self.unrelated_data += 1
  1660. return
  1661. elif self.search_key == '999维生素C咀嚼片':
  1662. if '999' not in title_info or temp_search_key not in title_info:
  1663. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1664. self.swipe_back(1)
  1665. self.unrelated_data += 1
  1666. return
  1667. elif '80' not in title_info:
  1668. print(f"当前商品名称:{title_info} 不包含80品规")
  1669. self.swipe_back(1)
  1670. self.unrelated_data += 1
  1671. return
  1672. elif self.search_key == '999精氨酸布洛芬颗粒':
  1673. if '999' not in title_info or temp_search_key not in title_info:
  1674. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1675. self.swipe_back(1)
  1676. self.unrelated_data += 1
  1677. return
  1678. elif '9' not in title_info:
  1679. print(f"当前商品名称:{title_info} 不包含9品规")
  1680. self.swipe_back(1)
  1681. self.unrelated_data += 1
  1682. return
  1683. elif self.search_key == '999阿奇霉素片':
  1684. if '999' not in title_info or temp_search_key not in title_info:
  1685. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1686. self.swipe_back(1)
  1687. self.unrelated_data += 1
  1688. return
  1689. elif '0.25g*6' not in title_info:
  1690. print(f"当前商品名称:{title_info} 不包含0.25g*6品规")
  1691. self.swipe_back(1)
  1692. self.unrelated_data += 1
  1693. return
  1694. elif self.search_key == '999感冒清热颗粒6g*10':
  1695. if '999' not in title_info or temp_search_key not in title_info:
  1696. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1697. self.swipe_back(1)
  1698. self.unrelated_data += 1
  1699. return
  1700. elif '6g*10' not in title_info:
  1701. print(f"当前商品名称:{title_info} 不包含6g*10品规")
  1702. self.swipe_back(1)
  1703. self.unrelated_data += 1
  1704. return
  1705. elif self.search_key == '999选平硝酸咪康唑乳膏20g':
  1706. if temp_search_key not in title_info:
  1707. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1708. self.swipe_back(1)
  1709. self.unrelated_data += 1
  1710. return
  1711. elif ('999' not in title_info) and ('选平' not in title_info):
  1712. print(f"当前商品名称:{title_info} 不包含关键字:999或 选平")
  1713. self.swipe_back(1)
  1714. self.unrelated_data += 1
  1715. return
  1716. elif '20g' not in title_info:
  1717. print(f"当前商品名称:{title_info} 不包含20g品规")
  1718. self.swipe_back(1)
  1719. self.unrelated_data += 1
  1720. return
  1721. elif self.search_key == '999糠酸莫米松乳膏10g':
  1722. if '999' not in title_info or temp_search_key not in title_info:
  1723. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1724. self.swipe_back(1)
  1725. self.unrelated_data += 1
  1726. return
  1727. elif '10g' not in title_info:
  1728. print(f"当前商品名称:{title_info} 不包含10g品规")
  1729. self.swipe_back(1)
  1730. self.unrelated_data += 1
  1731. return
  1732. elif self.search_key == '999补脾益肠丸':
  1733. if temp_search_key not in title_info:
  1734. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1735. self.swipe_back(1)
  1736. self.unrelated_data += 1
  1737. return
  1738. elif ('999' not in title_info) and ('三九' not in title_info):
  1739. print(f"当前商品名称:{title_info} 不包含关键字:999或 三九")
  1740. self.swipe_back(1)
  1741. self.unrelated_data += 1
  1742. return
  1743. elif self.search_key == '999壮骨关节丸6g*20':
  1744. if '999' not in title_info or temp_search_key not in title_info:
  1745. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1746. self.swipe_back(1)
  1747. self.unrelated_data += 1
  1748. return
  1749. elif '6g*20' not in title_info:
  1750. print(f"当前商品名称:{title_info} 不包含6g*20品规")
  1751. self.swipe_back(1)
  1752. self.unrelated_data += 1
  1753. return
  1754. elif self.search_key == '999正天丸6g*15':
  1755. if '999' not in title_info or temp_search_key not in title_info:
  1756. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1757. self.swipe_back(1)
  1758. self.unrelated_data += 1
  1759. return
  1760. elif '6g*15' not in title_info:
  1761. print(f"当前商品名称:{title_info} 不包含6g*15品规")
  1762. self.swipe_back(1)
  1763. self.unrelated_data += 1
  1764. return
  1765. elif self.search_key == '999藿香正气合剂10ml*6':
  1766. if '999' not in title_info or temp_search_key not in title_info:
  1767. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1768. self.swipe_back(1)
  1769. self.unrelated_data += 1
  1770. return
  1771. elif '10ml*6' not in title_info:
  1772. print(f"当前商品名称:{title_info} 不包含10ml*6品规")
  1773. self.swipe_back(1)
  1774. self.unrelated_data += 1
  1775. return
  1776. elif self.search_key == '999藿香正气合剂10ml*10':
  1777. if '999' not in title_info or temp_search_key not in title_info:
  1778. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1779. self.swipe_back(1)
  1780. self.unrelated_data += 1
  1781. return
  1782. elif '10ml*10' not in title_info:
  1783. print(f"当前商品名称:{title_info} 不包含10ml*10品规")
  1784. self.swipe_back(1)
  1785. self.unrelated_data += 1
  1786. return
  1787. elif self.search_key == '999小儿止咳糖浆120':
  1788. if '999' not in title_info or temp_search_key not in title_info:
  1789. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1790. self.swipe_back(1)
  1791. self.unrelated_data += 1
  1792. return
  1793. elif '120' not in title_info:
  1794. print(f"当前商品名称:{title_info} 不包含120品规")
  1795. self.swipe_back(1)
  1796. self.unrelated_data += 1
  1797. return
  1798. elif self.search_key == '999小儿止咳糖浆225':
  1799. if '999' not in title_info or temp_search_key not in title_info:
  1800. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1801. self.swipe_back(1)
  1802. self.unrelated_data += 1
  1803. return
  1804. elif '225' not in title_info:
  1805. print(f"当前商品名称:{title_info} 不包含225品规")
  1806. self.swipe_back(1)
  1807. self.unrelated_data += 1
  1808. return
  1809. elif self.search_key == '999小儿感冒颗粒6g*10':
  1810. if '999' not in title_info or temp_search_key not in title_info:
  1811. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1812. self.swipe_back(1)
  1813. self.unrelated_data += 1
  1814. return
  1815. elif '6g*10' not in title_info:
  1816. print(f"当前商品名称:{title_info} 不包含6g*10品规")
  1817. self.swipe_back(1)
  1818. self.unrelated_data += 1
  1819. return
  1820. elif self.search_key == '999小儿感冒颗粒6g*24':
  1821. if '999' not in title_info or temp_search_key not in title_info:
  1822. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1823. self.swipe_back(1)
  1824. self.unrelated_data += 1
  1825. return
  1826. elif '6g*24' not in title_info:
  1827. print(f"当前商品名称:{title_info} 不包含6g*24品规")
  1828. self.swipe_back(1)
  1829. self.unrelated_data += 1
  1830. return
  1831. elif self.search_key == '999小儿氨酚黄那敏颗粒6g*10袋':
  1832. if '999' not in title_info or temp_search_key not in title_info:
  1833. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1834. self.swipe_back(1)
  1835. self.unrelated_data += 1
  1836. return
  1837. elif '6g*10' not in title_info:
  1838. print(f"当前商品名称:{title_info} 不包含6g*10品规")
  1839. self.swipe_back(1)
  1840. self.unrelated_data += 1
  1841. return
  1842. elif self.search_key == '999小儿氨酚黄那敏颗粒6g*20袋':
  1843. if '999' not in title_info or temp_search_key not in title_info:
  1844. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1845. self.swipe_back(1)
  1846. self.unrelated_data += 1
  1847. return
  1848. elif '6g*20' not in title_info:
  1849. print(f"当前商品名称:{title_info} 不包含6g*20品规")
  1850. self.swipe_back(1)
  1851. self.unrelated_data += 1
  1852. return
  1853. elif self.search_key == '999感冒灵颗粒':
  1854. if '999' not in title_info or temp_search_key not in title_info:
  1855. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1856. self.swipe_back(1)
  1857. self.unrelated_data += 1
  1858. return
  1859. elif '10g*9' not in title_info:
  1860. print(f"当前商品名称:{title_info} 不包含10g*9品规")
  1861. self.swipe_back(1)
  1862. self.unrelated_data += 1
  1863. return
  1864. elif self.search_key == '999皮炎平复方醋酸地塞米松乳膏20':
  1865. if temp_search_key not in title_info:
  1866. print(f"当前商品名称:{title_info} 不包含关键字:{temp_search_key}")
  1867. self.swipe_back(1)
  1868. self.unrelated_data += 1
  1869. return
  1870. # elif ('999' not in title_info) and ('皮炎平' not in title_info):
  1871. elif '999' not in title_info:
  1872. print(f"当前商品名称:{title_info} 不包含关键字:999或 皮炎平")
  1873. self.swipe_back(1)
  1874. self.unrelated_data += 1
  1875. return
  1876. elif '20g' not in title_info:
  1877. print(f"当前商品名称:{title_info} 不包含20g品规")
  1878. self.swipe_back(1)
  1879. self.unrelated_data += 1
  1880. return
  1881. elif self.search_key == '999糠酸莫米松凝胶10':
  1882. if '999' not in title_info or temp_search_key not in title_info:
  1883. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1884. self.swipe_back(1)
  1885. self.unrelated_data += 1
  1886. return
  1887. elif '10' not in title_info:
  1888. print(f"当前商品名称:{title_info} 不包含10品规")
  1889. self.swipe_back(1)
  1890. self.unrelated_data += 1
  1891. return
  1892. elif self.search_key == '999板蓝根颗粒10g*20':
  1893. if '999' not in title_info or temp_search_key not in title_info:
  1894. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1895. self.swipe_back(1)
  1896. self.unrelated_data += 1
  1897. return
  1898. elif '10g*20' not in title_info:
  1899. print(f"当前商品名称:{title_info} 不包含10g*20品规")
  1900. self.swipe_back(1)
  1901. self.unrelated_data += 1
  1902. return
  1903. elif self.search_key == '999咽炎片0.26g*12片':
  1904. if '999' not in title_info or temp_search_key not in title_info:
  1905. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1906. self.swipe_back(1)
  1907. self.unrelated_data += 1
  1908. return
  1909. elif '0.26g*12' not in title_info and '0.26g*24' not in title_info:
  1910. print(f"当前商品名称:{title_info} 不包含0.26g*12 和 0.26g*24品规")
  1911. self.swipe_back(1)
  1912. self.unrelated_data += 1
  1913. return
  1914. elif self.search_key == '999感冒清热颗粒12g*18':
  1915. if '999' not in title_info or temp_search_key not in title_info:
  1916. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1917. self.swipe_back(1)
  1918. self.unrelated_data += 1
  1919. return
  1920. elif '12g*18' not in title_info:
  1921. print(f"当前商品名称:{title_info} 不包含12g*18品规")
  1922. self.swipe_back(1)
  1923. self.unrelated_data += 1
  1924. return
  1925. elif self.search_key == '999小儿咽扁颗粒8g*10袋':
  1926. if '999' not in title_info or temp_search_key not in title_info:
  1927. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1928. self.swipe_back(1)
  1929. self.unrelated_data += 1
  1930. return
  1931. elif '8g*10' not in title_info:
  1932. print(f"当前商品名称:{title_info} 不包含8g*10品规")
  1933. self.swipe_back(1)
  1934. self.unrelated_data += 1
  1935. return
  1936. elif self.search_key == '999小柴胡颗粒10g*15':
  1937. if '999' not in title_info or temp_search_key not in title_info:
  1938. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1939. self.swipe_back(1)
  1940. self.unrelated_data += 1
  1941. return
  1942. elif '15' not in title_info:
  1943. print(f"当前商品名称:{title_info} 不包含15品规")
  1944. self.swipe_back(1)
  1945. self.unrelated_data += 1
  1946. return
  1947. else:
  1948. if '999' not in title_info or temp_search_key not in title_info:
  1949. print(f"当前商品名称:{title_info} 不包含关键字:{self.search_key}")
  1950. self.swipe_back(1)
  1951. self.unrelated_data += 1
  1952. return
  1953. else:
  1954. if self.search_key == '史达功右美沙芬愈创甘油醚糖浆120':
  1955. temp_search_key = self.search_key.replace('史达功', '')
  1956. temp_search_key = temp_search_key.replace('120', '')
  1957. if '史达功' not in title_info or temp_search_key not in title_info:
  1958. print(f'药品标题未包含药品关键字:-->{temp_search_key}')
  1959. self.swipe_back(1)
  1960. self.unrelated_data += 1
  1961. return
  1962. elif '120' not in title_info:
  1963. print(f"当前商品名称:{title_info} 不包含120品规")
  1964. self.swipe_back(1)
  1965. self.unrelated_data += 1
  1966. return
  1967. elif self.search_key == '三九胃泰养胃舒颗粒8袋':
  1968. temp_search_key = self.search_key.replace('三九胃泰', '')
  1969. temp_search_key = temp_search_key.replace('8袋', '')
  1970. if '三九胃泰' not in title_info or temp_search_key not in title_info:
  1971. print(f'药品标题未包含药品关键字:-->{temp_search_key}')
  1972. self.swipe_back(1)
  1973. self.unrelated_data += 1
  1974. return
  1975. elif '8袋' not in title_info:
  1976. print(f"当前商品名称:{title_info} 不包含8袋品规")
  1977. self.swipe_back(1)
  1978. self.unrelated_data += 1
  1979. return
  1980. elif self.search_key == '三九复方金银花颗粒10g*8袋':
  1981. temp_search_key = self.search_key.replace('三九', '')
  1982. temp_search_key = temp_search_key.replace('10g*8袋', '')
  1983. if '三九' not in title_info or temp_search_key not in title_info:
  1984. print(f'药品标题未包含药品关键字:-->{temp_search_key}')
  1985. self.swipe_back(1)
  1986. self.unrelated_data += 1
  1987. return
  1988. elif '10g*8' not in title_info:
  1989. print(f"当前商品名称:{title_info} 不包含10g*8品规")
  1990. self.swipe_back(1)
  1991. self.unrelated_data += 1
  1992. return
  1993. elif self.search_key == '必无忧盐酸特比萘芬喷雾剂30ml':
  1994. temp_search_key = self.search_key.replace('必无忧', '')
  1995. temp_search_key = temp_search_key.replace('30ml', '')
  1996. if '必无忧' not in title_info or temp_search_key not in title_info:
  1997. print(f'药品标题未包含药品关键字:-->{temp_search_key}')
  1998. self.swipe_back(1)
  1999. self.unrelated_data += 1
  2000. return
  2001. elif '30' not in title_info:
  2002. print(f"当前商品名称:{title_info} 不包含30品规")
  2003. self.swipe_back(1)
  2004. self.unrelated_data += 1
  2005. return
  2006. elif self.search_key == '佳美舒阿奇霉素肠溶胶囊4':
  2007. temp_search_key = self.search_key.replace('佳美舒', '')
  2008. temp_search_key = temp_search_key.replace('4', '')
  2009. if '佳美舒' not in title_info or temp_search_key not in title_info:
  2010. print(f'药品标题未包含药品关键字:-->{temp_search_key}')
  2011. self.swipe_back(1)
  2012. self.unrelated_data += 1
  2013. return
  2014. elif '4' not in title_info and '8' not in title_info:
  2015. print(f"当前商品名称:{title_info} 不包含4品规或8品规")
  2016. self.swipe_back(1)
  2017. self.unrelated_data += 1
  2018. return
  2019. elif self.search_key == '三九胃泰颗粒20g*10':
  2020. temp_search_key = self.search_key.replace('20g*10', '')
  2021. if temp_search_key not in title_info:
  2022. print(f'药品标题未包含药品关键字:-->{temp_search_key}')
  2023. self.swipe_back(1)
  2024. self.unrelated_data += 1
  2025. return
  2026. elif '20g*10' not in title_info:
  2027. print(f"当前商品名称:{title_info} 不包含20g*10品规")
  2028. self.swipe_back(1)
  2029. self.unrelated_data += 1
  2030. return
  2031. elif self.search_key == '三九胃泰颗粒2.5g*6':
  2032. temp_search_key = self.search_key.replace('2.5g*6', '')
  2033. if temp_search_key not in title_info:
  2034. print(f'药品标题未包含药品关键字:-->{temp_search_key}')
  2035. self.swipe_back(1)
  2036. self.unrelated_data += 1
  2037. return
  2038. elif '2.5g*6' not in title_info:
  2039. print(f"当前商品名称:{title_info} 不包含2.5g*6品规")
  2040. self.swipe_back(1)
  2041. self.unrelated_data += 1
  2042. return
  2043. elif self.search_key == '三九胃泰颗粒20g*6袋':
  2044. temp_search_key = self.search_key.replace('20g*6袋', '')
  2045. if temp_search_key not in title_info:
  2046. print(f'药品标题未包含药品关键字:-->{temp_search_key}')
  2047. self.swipe_back(1)
  2048. self.unrelated_data += 1
  2049. return
  2050. elif '20g*6' not in title_info:
  2051. print(f"当前商品名称:{title_info} 不包含20g*6品规")
  2052. self.swipe_back(1)
  2053. self.unrelated_data += 1
  2054. return
  2055. elif self.search_key == '顺峰酮康他索乳膏':
  2056. temp_search_key = self.search_key.replace('顺峰', '')
  2057. if temp_search_key not in title_info or '顺峰' not in title_info:
  2058. print(f'药品标题未包含药品关键字:-->{temp_search_key}')
  2059. self.swipe_back(1)
  2060. self.unrelated_data += 1
  2061. return
  2062. elif self.search_key == '速复康磷酸奥司他韦胶囊75mg*10':
  2063. temp_search_key = self.search_key.replace('速复康', '')
  2064. temp_search_key = temp_search_key.replace('75mg*10', '')
  2065. if '佳美舒' not in title_info or temp_search_key not in title_info:
  2066. print(f'药品标题未包含药品关键字:-->{temp_search_key}')
  2067. self.swipe_back(1)
  2068. self.unrelated_data += 1
  2069. return
  2070. elif '75mg*10' not in title_info:
  2071. print(f"当前商品名称:{title_info} 不包含75mg*10品规")
  2072. self.swipe_back(1)
  2073. self.unrelated_data += 1
  2074. return
  2075. else:
  2076. if self.search_key not in title_info:
  2077. print(f'药品标题未包含药品关键字:-->{self.search_key}')
  2078. self.swipe_back(1)
  2079. self.unrelated_data += 1
  2080. return
  2081. # temp_search_key = self.search_key
  2082. # if self.search_key == '三九胃泰颗粒':
  2083. # temp_search_key = '三九胃泰' #兼容三九胃泰 温胃舒颗粒
  2084. # elif '999' in self.search_key:
  2085. # temp_search_key = self.search_key.replace('999', '')
  2086. # if '999' in self.search_key:
  2087. # if ('999' not in title_info) or (temp_search_key not in title_info):
  2088. # print(f'药品标题未包含药品关键字:-->{temp_search_key}和未包含999')
  2089. # self.swipe_back(1)
  2090. # self.unrelated_data += 1
  2091. # return
  2092. # else:
  2093. # if temp_search_key not in title_info:
  2094. # print(f'药品标题未包含药品关键字:-->{temp_search_key}')
  2095. # self.swipe_back(1)
  2096. # self.unrelated_data += 1
  2097. # return
  2098. else:
  2099. print('标题获取为空')
  2100. self.swipe_back(1)
  2101. return
  2102. # 第一次没有获取到价格
  2103. if not min_price:
  2104. min_price = self.drug_price() # 最低价格 第二次获取
  2105. if not min_price:
  2106. print('提取价格出错,回退到列表页')
  2107. self.swipe_back(1)
  2108. self.unrelated_data += 1
  2109. return
  2110. # 商品链接 分享链接
  2111. product_link = self.get_product_link()
  2112. time.sleep(2)
  2113. if self.search_key == '999小儿止咳糖浆' or self.search_key == '999小儿氨酚黄那敏颗粒' or self.search_key == '999小儿感冒颗粒':
  2114. shop = self.get_shop_name()
  2115. else:
  2116. for i in range(15):
  2117. if self.d(textStartsWith="进店").exists:
  2118. print('开始获取店铺名')
  2119. break
  2120. screen_width = self.d.info['displayWidth']
  2121. screen_height = self.d.info['displayHeight']
  2122. # self.d.swipe(screen_width // 2, screen_height - 400, screen_width // 2, 400, duration=0.2)
  2123. self.d.swipe_ext("up", scale=0.3)
  2124. time.sleep(self.get_sleep_time())
  2125. if self.d(textStartsWith="进店").exists:
  2126. print('可以开始获取店铺名')
  2127. # shop = self.get_shop_name()
  2128. shop = self.get_shop_name()
  2129. if not shop:
  2130. print('当前店铺名称为空')
  2131. self.swipe_back(1)
  2132. self.unrelated_data += 1
  2133. return
  2134. # 爬取日期
  2135. scrape_date = self.get_current_date()
  2136. if self.search_key == '999小柴胡颗粒10g*15':
  2137. dup_search_key = '999小柴胡颗粒'
  2138. else:
  2139. dup_search_key = self.search_key
  2140. dup_data = {'search_key': dup_search_key, 'min_price': min_price, 'shop': shop, 'scrape_date': scrape_date,
  2141. 'platform': '拼多多'}
  2142. if self.data_is_exists(dup_data):
  2143. print('存在相同数据不入库')
  2144. self.swipe_back(1)
  2145. return
  2146. is_has_instructions = self.has_instructions()
  2147. # print(f'是否有说明书:{is_has_instructions}')
  2148. self.loggerPdd.info(f'是否有说明书:{is_has_instructions}')
  2149. # 生产日期为空
  2150. manufacture_date = ''
  2151. # 执政信息
  2152. # if is_has_enter_shop:
  2153. # license_info = self.get_license_info()
  2154. # business_license_company = license_info["单位名称"]
  2155. # credit_code = license_info['社会信用代码']
  2156. # city_str = license_info['地址']
  2157. # # 先把省份啥的替换掉
  2158. # city_sub_str = re.sub(r'[u4e00-\u9fa5]+省', '', city_str)
  2159. # try:
  2160. # city = re.search(r'[\u4e00-\u9fa5]+?(市|区|县)', city_sub_str).group(0)
  2161. # except:
  2162. # city = city_sub_str
  2163. # try:
  2164. # province = self.city2province[city]
  2165. # except:
  2166. # province = ''
  2167. # self.swipe_back(2)
  2168. # else:
  2169. # business_license_company = ''
  2170. # credit_code = ''
  2171. # city = ''
  2172. # province = ''
  2173. business_license_company = ''
  2174. # credit_code = ''
  2175. credit_code = ext
  2176. city = ''
  2177. province = ''
  2178. # 说明书等信息
  2179. if is_has_instructions:
  2180. try:
  2181. instructions_info = self.get_instructions_data()
  2182. # print('说明书相关信息:', instructions_info)
  2183. expiry_date = instructions_info['有效期'].strip('。')
  2184. manufacturer = instructions_info['生产单位'].strip('。')
  2185. approval_number = instructions_info['批准文号'].strip('。')
  2186. specifications = instructions_info['产品规格'].strip('。')
  2187. except Exception as e:
  2188. print(f'获取详情页规格参数出错:{e}')
  2189. self.swipe_back(2)
  2190. return
  2191. else:
  2192. expiry_date = ''
  2193. manufacturer = ''
  2194. approval_number = ''
  2195. specifications = ''
  2196. # if self.search_key == '999小柴胡颗粒':
  2197. # if '10g*9' in specifications or '10克x9' in specifications or '10g*15' in specifications or '10克/袋*9' in specifications:
  2198. # print("111")
  2199. # else:
  2200. # self.swipe_back(1)
  2201. # return
  2202. # elif self.search_key == '':
  2203. # if '10ml*12' in specifications or '10ml*18' in specifications:
  2204. # print(222)
  2205. # else:
  2206. # self.swipe_back(1)
  2207. # return
  2208. self.unrelated_data = 0
  2209. # 商品链接
  2210. # product_link = ''
  2211. # 爬取省份
  2212. scrape_province = '广东' # 这里先默认广东
  2213. # 是否有货
  2214. availability = ''
  2215. if self.search_key == '999小柴胡颗粒10g*15':
  2216. save_search_key = '999小柴胡颗粒'
  2217. else:
  2218. save_search_key = self.search_key
  2219. save_data = {
  2220. 'product': title_info,
  2221. 'min_price': min_price,
  2222. 'manufacture_date': manufacture_date,
  2223. 'expiry_date': expiry_date,
  2224. 'shop': shop,
  2225. 'business_license_company': business_license_company,
  2226. 'province': province,
  2227. 'city': city,
  2228. 'manufacturer': manufacturer,
  2229. 'specification': specifications,
  2230. 'approval_number': approval_number,
  2231. 'product_link': product_link,
  2232. 'scrape_date': scrape_date,
  2233. 'scrape_province': scrape_province,
  2234. 'availability': availability,
  2235. 'credit_code': credit_code,
  2236. 'platform': '拼多多',
  2237. 'search_key': save_search_key,
  2238. 'number': 1
  2239. }
  2240. # print(f'待插入数据:{save_data}')
  2241. self.save_to_database(save_data)
  2242. self.swipe_back(1)
  2243. # 获取店铺信息start 2025-07-28
  2244. '''
  2245. #不获取店铺信息
  2246. #1、判断店铺名称是否已存在
  2247. shop_is_exists = self.shop_is_exists_database(shop)
  2248. #2、获取店铺资质 是否存在
  2249. # is_has_shop_qualifications = self.has_shop_qualifications()
  2250. if not shop_is_exists :
  2251. print('开始获取店铺信息')
  2252. #点击店铺,点击店铺标题,点击店铺资质
  2253. # license_info = self.get_license_info_ex()
  2254. else:
  2255. #日志中加上店铺名称
  2256. self.loggerPdd.info(f'店铺{shop}信息已存在数据库')
  2257. #获取店铺信息end
  2258. '''
  2259. if self.distinct_target():
  2260. print('已到达搜索列表页')
  2261. else:
  2262. for i in range(2):
  2263. self.swipe_back(1)
  2264. # 最外部有个定位按钮
  2265. if self.distinct_target():
  2266. break
  2267. def main(self, device_id, search_key_length, keyword_idx):
  2268. spider_no = 0
  2269. self.connect_devices(device_id)
  2270. time.sleep(self.get_sleep_time())
  2271. print("搜索前,先重启APP")
  2272. # 重新开启拼多多应用
  2273. self.restart_app()
  2274. # 搜索关键字
  2275. self.enter_target_page()
  2276. # if keyword_idx == 0:
  2277. # print("搜索前,先重启APP")
  2278. # # 重新开启拼多多应用
  2279. # self.restart_app()
  2280. # # 搜索关键字
  2281. # self.enter_target_page()
  2282. # else:
  2283. # print("清空前面的文字,再输入关键词")
  2284. # self.d.send_keys(self.search_key, clear=True)
  2285. # time.sleep(self.get_sleep_time())
  2286. # print("点击搜索")
  2287. # self.d.xpath('//*[@text="搜索"]').click()
  2288. # time.sleep(self.get_sleep_time())
  2289. # # 3. 容错处理:点击失败时的兜底逻辑
  2290. # self.swipe_up()
  2291. for idx in range(300):
  2292. print(f'第{idx + 1}页')
  2293. if spider_no > 30:
  2294. time.sleep(300)
  2295. spider_no = 0
  2296. if self.unrelated_data > 10:
  2297. print(f'[{self.program_start_time}]----{self.search_key}----连续超过10个不达标的数据则停止采集')
  2298. print(f"[程序启动时间:{self.program_start_time}-----程序结束时间:{self.app_current_time()}]----搜索关键词:{self.search_key}----点击了{self.click_counts}个商品")
  2299. # self.swipe_down()
  2300. # time.sleep(self.get_sleep_time()) # 下滑后等待页面稳定
  2301. #
  2302. # click_success = self.click_target_product_by_search_key(fuzzy_match=False)
  2303. # if not click_success:
  2304. # print(f"⚠️ 关键词「{self.search_key}」商品点击失败")
  2305. # return
  2306. #
  2307. # print("点击搜索框")
  2308. # self.d(className='android.widget.EditText').click()
  2309. # time.sleep(self.get_sleep_time())
  2310. if keyword_idx == search_key_length - 1:
  2311. print("程序最后一个品规采集完毕,返回主屏幕")
  2312. self.d.press("home")
  2313. # 连续超过10个不达标的数据则停止采集
  2314. break
  2315. if self.max_counts >= 300 and self.search_key == '999糠酸莫米松凝胶10':
  2316. print('enough')
  2317. break
  2318. # 售罄次数大于4基本就是号废了但是如果下次点击不会出现这种情况就要重置为0
  2319. if self.sold_out_counts > 4:
  2320. print(
  2321. f"[程序启动时间:{self.program_start_time}-----程序结束时间:{self.app_current_time()}]----搜索关键词:{self.search_key}----点击了{self.click_counts}个商品")
  2322. print("====商品已售罄4次,结束采集(号不能用),返回主屏幕====")
  2323. self.d.press('home')
  2324. break
  2325. if idx == 0:
  2326. drug_lis = self.d.xpath(
  2327. '//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.FrameLayout[2]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.support.v7.widget.RecyclerView[1]/android.widget.FrameLayout').all()
  2328. else:
  2329. for i in range(1, 6):
  2330. drug_xpath = f'/hierarchy/android.widget.FrameLayout[{i}]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.support.v7.widget.RecyclerView[1]/android.widget.FrameLayout'
  2331. drug_lis = self.d.xpath(
  2332. f'/hierarchy/android.widget.FrameLayout[{i}]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.support.v7.widget.RecyclerView[1]/android.widget.FrameLayout').all()
  2333. if drug_lis:
  2334. break
  2335. print('数量', len(drug_lis))
  2336. for idd, drug_one in enumerate(drug_lis):
  2337. print(idd + 1, drug_one.info)
  2338. time.sleep(self.get_sleep_time())
  2339. # left = drug_one.info['bounds']['left']
  2340. top = drug_one.info['bounds']['top']
  2341. # right = drug_one.info['bounds']['right']
  2342. bottom = drug_one.info['bounds']['bottom']
  2343. # height = bottom - top
  2344. # 高度低于多少的不点击采集
  2345. # if bottom <= 1400 and top >= 258:
  2346. if bottom <= 1524 and top >= 258:
  2347. # print(f"这页的第{idd+1}个商品")
  2348. # #商品名称的xpath
  2349. # if idx == 0:
  2350. # product_tittle_xpath = f'//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.FrameLayout[2]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.support.v7.widget.RecyclerView[1]/android.widget.FrameLayout[{idd+2}]/android.widget.LinearLayout[1]/android.widget.FrameLayout[2]/android.widget.TextView'
  2351. # else:
  2352. # product_tittle_xpath = drug_xpath + f'[{idd+1}]/android.widget.LinearLayout[1]/android.widget.FrameLayout[2]/android.widget.TextView'
  2353. # print(f"商品名称的xpath:{product_tittle_xpath}")
  2354. # if self.d.xpath(product_tittle_xpath).exists:
  2355. # # product_title = self.d.xpath(product_tittle_xpath).info['contentDescription']
  2356. # print(f"列表当前info:{self.d.xpath(product_tittle_xpath).info}")
  2357. # product_title = self.d.xpath(product_tittle_xpath).text
  2358. # print(f"列表当前商品名称:{product_title}")
  2359. # if '999' in self.search_key:
  2360. # temp_search_key = self.search_key.replace('999', '')
  2361. # if '999' not in product_title or temp_search_key not in product_title:
  2362. # print(f"当前商品名称:{product_title} 不包含关键字:{self.search_key}")
  2363. # continue
  2364. # else:
  2365. # if self.search_key not in product_title.replace(' ', ''):
  2366. # continue
  2367. # else:
  2368. # print(f"列表当前商品路径不存在")
  2369. drug_one.click()
  2370. self.click_counts += 1
  2371. time.sleep(self.get_sleep_time())
  2372. # 先判断是否售罄次数是否大于4
  2373. if self.sold_out_counts >= 4:
  2374. print(f"[程序启动时间:{self.program_start_time}-----程序结束时间:{self.app_current_time()}]----搜索关键词:{self.search_key}----点击了{self.click_counts}个商品")
  2375. print("====这是在第一页有两个,商品已售罄4次,结束采集(号不能用)====")
  2376. time.sleep(self.get_sleep_time())
  2377. self.d.press('home')
  2378. return
  2379. # 已售罄 self.sold_out_counts += 1
  2380. if self.d.xpath('//*[contains(@text, "商品已售罄")]').wait(timeout=5):
  2381. print("======商品已售罄======")
  2382. self.sold_out_counts += 1
  2383. self.swipe_back(1)
  2384. continue
  2385. # 采集药品信息
  2386. try:
  2387. # 重置商品售罄次数
  2388. self.sold_out_counts = 0
  2389. self.integrate_data()
  2390. # 检测下是否回退到列表页
  2391. if self.distinct_target():
  2392. print('回退到列表页', True)
  2393. else:
  2394. print(f'[{self.app_current_time()}] 回退到列表页失败,终止采集')
  2395. print(f"[程序启动时间:{self.program_start_time}-----程序结束时间:{self.app_current_time()}]----搜索关键词:{self.search_key}----点击了{self.click_counts}个商品")
  2396. return
  2397. time.sleep(self.get_sleep_time())
  2398. spider_no += 1
  2399. except Exception as e:
  2400. print(f'采集药品详情数据出错:{e}')
  2401. self.loggerPdd.error(f'采集药品详情数据出错:{e}')
  2402. if not self.distinct_target():
  2403. for i in range(1):
  2404. self.swipe_back(1)
  2405. # 最外部有个列表按钮
  2406. if self.distinct_target():
  2407. break
  2408. if i == 0 and not self.distinct_target():
  2409. print('页面出错,退出采集')
  2410. return
  2411. else:
  2412. continue
  2413. if self.d(textStartsWith="抱歉,没有更多商品啦~").exists:
  2414. print('已经到达列表页最底部')
  2415. break
  2416. print('开始滑入下一页')
  2417. # search_list = self.d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.support.v7.widget.RecyclerView[1]').info
  2418. # bounds = search_list['bounds']
  2419. # try:
  2420. # top = drug_lis[0].info['bounds']['top']
  2421. # except Exception as e:
  2422. # print(f'获取滑动参数top出错:{e}')
  2423. # top = 250
  2424. # search_list = self.d.xpath('//android.support.v7.widget.RecyclerView').info
  2425. # bottom = search_list['bounds']['bottom']
  2426. # end_y = 1400 + top - bottom + 162
  2427. # if end_y < 150:
  2428. # end_y = 150
  2429. end_y = 300
  2430. # self.d.swipe(200, 1400, 200, 1400 + bounds['top'] - bounds['bottom'] + 162, 0.4)
  2431. self.d.swipe(200, 1400, 200, end_y, 0.4)
  2432. time.sleep(self.get_sleep_time())
  2433. def unitest(self):
  2434. """
  2435. 单元测试
  2436. :return:
  2437. """
  2438. # device_id = '21885f5'
  2439. # # self.connect_devices(device_id)
  2440. # # self.screenshot_the_business_license()
  2441. # # cropped_screenshot_path = 'cropped_screenshot.png'
  2442. # # self.get_ocr_res(cropped_screenshot_path)
  2443. # shop_name = '我的店铺'
  2444. # base_path = r'D:\work\dfwy_spider\drug_data\pdd\screenshot'
  2445. # cropped_screenshot_path = os.path.join(base_path, shop_name + '.png')
  2446. # os.makedirs(base_path, exist_ok=True)
  2447. # print(cropped_screenshot_path)
  2448. # cropped_screenshot_path = 'D:\\work\\dfwy_spider\\drug_data\\pdd\\screenshot\\' + shop_name + '.png'
  2449. # print(cropped_screenshot_path)
  2450. # time.sleep(10000)
  2451. ocr_res = self.get_ocr_res('ceshi1.jpg')
  2452. print(f'ocr_res:{ocr_res}')
  2453. # 获取当前时间
  2454. current_time = datetime.datetime.now()
  2455. # 格式化为时分秒
  2456. time_str = current_time.strftime("%H-%M-%S")
  2457. # 生成随机的 8 位字符串
  2458. random_str = secrets.token_hex(4) # 生成 4 个字节的随机字符串,转换为 8 位十六进制字符串
  2459. screenshot_path = 'instructionscreenshot1-' + time_str + '-' + random_str + '.png'
  2460. print(screenshot_path)
  2461. # if ocr_res:
  2462. # for item in ocr_res:
  2463. # if '拖动滑块完成' in item['words']:
  2464. # print("滑块验证")
  2465. # break
  2466. # print("ocr_res end")
  2467. # company_name = ''
  2468. # reg_number = ''
  2469. # address = ''
  2470. # if ocr_res:
  2471. # for item in ocr_res:
  2472. # if '企业注册号' in item['words']:
  2473. # # print('come in 111')
  2474. # reg_number = item['words'].split(':', 1)[1].strip()
  2475. # elif '企业名称' in item['words']:
  2476. # # print('come in 222')
  2477. # company_name = item['words'].split(':', 1)[1].strip()
  2478. # elif '所:' in item['words']:
  2479. # # print('come in 333')
  2480. # address = item['words'].split(':', 1)[1].strip()
  2481. # # 输出结果
  2482. # print("企业注册号:", reg_number)
  2483. # print("企业名称:", company_name)
  2484. # print("住所:", address)
  2485. # screenshot_verify_path = 'screenshot_verify.png'
  2486. # img = cv2.imread(screenshot_verify_path)
  2487. # # 指定裁剪区域 (left, top, right, bottom)
  2488. # left = 118
  2489. # top = 478
  2490. # right = 602
  2491. # bottom = 722
  2492. # cropped_verify_img = img[top:bottom, left:right]
  2493. # cropped_verify_creenshot_path = 'cropped_verify_screenshot.png'
  2494. # cv2.imwrite(cropped_verify_creenshot_path, cropped_verify_img)
  2495. # print('裁剪完成')
  2496. time.sleep(100000)
  2497. title_info = '云南白药 参苓健脾胃颗粒10袋 补脾健胃利湿止泻 脾胃虚弱 饮食不消 或泻或吐 形瘦色萎 神疲乏力 5盒装(补脾健胃)'
  2498. min_price = 85
  2499. shop = '堂鹭北大药房旗舰店'
  2500. scrape_date = '2025-03-19'
  2501. dup_data = {'product': title_info, 'min_price': min_price, 'shop': shop, 'scrape_date': scrape_date}
  2502. print(self.data_is_exists(dup_data))
  2503. # pdd
  2504. def main():
  2505. # 999感冒清热颗粒、 三九胃泰颗粒
  2506. # 暂时不需要的:
  2507. # '999小儿止咳糖浆'
  2508. # '999小儿氨酚黄那敏颗粒'
  2509. # '999小儿感冒颗粒'
  2510. # '999抗病毒口服液10ml*6支'
  2511. # '今维多赐多康牌蛋白粉',
  2512. # '必无忧盐酸特比萘芬喷雾剂30ml'
  2513. # '999冰连清咽'
  2514. # '999复方苦参肠炎康片12片'
  2515. # '999强力枇杷露16袋'
  2516. # '999三蛇胆川贝膏138'
  2517. # '999维生素E.C颗粒9袋'
  2518. # '三九胃泰养胃舒颗粒8袋'
  2519. # '999止泻利颗粒15g*8'
  2520. # '史达功右美沙芬愈创甘油醚糖浆120'
  2521. # '999复方氨酚烷胺胶囊6粒'
  2522. # '999可调式生理性海水鼻腔喷雾50'
  2523. # '999小儿止咳糖浆120' #不低于19.8
  2524. # '999小儿止咳糖浆225' #禁止挂网
  2525. # '999小儿感冒颗粒6g*10' #不低于24.9
  2526. # '999小儿感冒颗粒6g*24' #禁止挂网
  2527. # '999小儿氨酚黄那敏颗粒6g*10袋' #不低于15.8
  2528. # '999小儿氨酚黄那敏颗粒6g*20袋' #禁止挂网
  2529. # '999小儿咽扁颗粒8g*10袋' #仅限999官旗店
  2530. # '999阿奇霉素片'
  2531. # OTC
  2532. # '999银菊清咽颗粒' #没有数据
  2533. # '999感冒清热颗粒6g*10'
  2534. # '999选平硝酸咪康唑乳膏20g'
  2535. # '999糠酸莫米松乳膏10g'
  2536. # '999表虚感冒颗粒' #没有数据
  2537. # '999补脾益肠丸'
  2538. # '999壮骨关节胶囊'
  2539. # '999壮骨关节丸6g*20'
  2540. # '999正天丸6g*15'
  2541. # '999正天胶囊'
  2542. # '三九胃泰胶囊'
  2543. # '三九胃泰颗粒20g*10'
  2544. # '三九胃泰颗粒2.5g*6'
  2545. # '999藿香正气合剂10ml*6',
  2546. # '999藿香正气合剂10ml*10',
  2547. # '999黄芪精',
  2548. # '999曲安奈德益康唑乳膏30g',
  2549. # '999葡萄糖酸锌口服溶液',
  2550. # '佳美舒阿奇霉素肠溶胶囊4'
  2551. # '三九复方金银花颗粒10g*8袋'
  2552. # '999精氨酸布洛芬颗粒'
  2553. # '999强力枇杷露150ml'
  2554. # '999强力枇杷露' #同时支持120,150和225ml
  2555. # '顺峰酮康他索乳膏' #包含10g和20g两个规格 10g 不低于7.5 20g 不低于12.5 '顺峰康王酮康他索乳膏'
  2556. # '999板蓝根颗粒10g*20' #不低于26.9
  2557. # '999复方氨酚烷胺胶囊12粒' #不低于17.9 #统一成:999复方氨酚烷胺胶囊
  2558. # '999复方氨酚烷胺胶囊10粒' #禁止挂网 #统一成:999复方氨酚烷胺胶囊
  2559. # '999复方氨酚烷胺胶囊6粒' #禁止挂网 #统一成:999复方氨酚烷胺胶囊
  2560. # '999咽炎片0.26g*12片' #不低于13.5 #999咽炎片0.26g*12片*2板改成 999咽炎片0.26g*12片
  2561. # '999荆防颗粒' #美团没有数据 #禁止挂网 拼多多也没数据
  2562. # '999小儿感冒宁颗粒' #禁止挂网 999小儿感冒宁颗粒2.5g*10袋 改成 999小儿感冒宁颗粒
  2563. # '999维生素C咀嚼片'
  2564. # '999感冒灵颗粒10g*9袋' #不低于15.5
  2565. # '999皮炎平复方醋酸地塞米松乳膏20' #不低于12.5
  2566. # '三九胃泰颗粒20g*6袋' #不低于13.5
  2567. # '999复方氨酚烷胺胶囊'
  2568. # '999感冒灵胶囊' #仅限999官旗店
  2569. # '速复康磷酸奥司他韦胶囊75mg*10' #美团没数据 # 禁止挂网 999磷酸奥司他韦胶囊75mg*10 改成 速复康磷酸奥司他韦胶囊75mg*10
  2570. # '999小儿感冒颗粒6g*10' #不低于24.9
  2571. # '999抗病毒口服液10ml',
  2572. # '999蒲地蓝消炎片',
  2573. # '999小柴胡颗粒10g*15',
  2574. # '999复方感冒灵颗粒',
  2575. # '999必无忧盐酸特比萘芬乳膏15'
  2576. # '999复方板蓝根颗粒15g*15袋'
  2577. # '999速复康布洛芬缓释胶囊'
  2578. # '999精氨酸布洛芬颗粒'
  2579. # '999强力枇杷露225ml'
  2580. # 2025-08-01最新 其中 藿香正气合剂两种规格 10支和6支 抗病毒口服液 12支和18支 蒲地蓝 24片 36片和44片 枇杷露225ml 小柴胡颗粒9袋和15袋 养胃舒 6袋 复方感冒灵颗粒15袋,
  2581. # 曲安奈德益康唑乳膏 30g 葡萄糖酸锌口服溶液 12支 18支 24支和30支,
  2582. # 1、999止泻利颗粒15g*8 没有数据 2、三九胃泰养胃舒颗粒8袋 没有数据 3、999三蛇胆川贝膏138 没有数据 4、999强力枇杷露16袋 没有数据 5、999复方苦参肠炎康片12片 6、999冰连清咽 没有数据
  2583. #############以下是日常采集的品规start##################
  2584. # '999养胃舒颗粒10g*10',
  2585. # '999复方感冒灵颗粒',
  2586. # '999感冒清热颗粒12g*18' #禁止挂网
  2587. # '999小儿感冒宁颗粒' #禁止挂网 999小儿感冒宁颗粒2.5g*10袋 改成 999小儿感冒宁颗粒
  2588. # '999小儿咽扁颗粒8g*10袋' #仅限999官旗店
  2589. # '999布洛芬混悬液'
  2590. #########2026春节采集的品规start################################
  2591. # '999藿香正气合剂'
  2592. # '999糠酸莫米松凝胶15',
  2593. # '999抗病毒口服液10ml*10'
  2594. # '999抗病毒口服液10ml*12'
  2595. # '999强力枇杷露225ml',
  2596. # '999糠酸莫米松凝胶10' #不低于26.9
  2597. #########2026春节采集的品规end################################
  2598. ############以下是日常采集的品规start###########################
  2599. #切
  2600. # '999糠酸莫米松凝胶10' #不低于26.9 √#304
  2601. # '999布洛芬混悬液100ml' √#0可不采
  2602. search_key_list = [
  2603. '999强力枇杷露120ml',
  2604. '999速复康布洛芬缓释胶囊0.3g*12',
  2605. '999速复康布洛芬缓释胶囊0.3g*6',
  2606. '999精氨酸布洛芬颗粒'
  2607. ]
  2608. # search_key_list = ['999板蓝根颗粒10g*20']
  2609. # search_key = '999板蓝根颗粒10g*20' # 参苓健脾胃颗粒 香砂平胃颗粒 舒肝颗粒 清肺化痰丸
  2610. # 设备序列号
  2611. # device_id = 'e2899b34'
  2612. # device_id = '369dcf96'
  2613. # device_id = '2e58510'
  2614. # device_id = 'ea4e4eb8'
  2615. # device_id = 'IZTOWWDQT45D49BU'
  2616. # device_id = 'INXCDAIR75FMMFGU'
  2617. # device_id = 'CMKFUSSG99ROR489'
  2618. # device_id = '95b2c764'
  2619. device_id = 'UCQGF6CQFMU8WKHI'
  2620. # device_id = 'U8ONIJJJS4CELVD6'
  2621. # device_id = 'OVFETO8PCY45E6A6'
  2622. # device_id = 'IRLZAAQCDMHYWKTS'
  2623. # device_id = 'DEZXWKUC7DJBLVPJ'
  2624. # device_id = 'U47HZDRG8XJBBURW'
  2625. # device_id = 'WWRO9LTGG6KFGQCM'
  2626. # device_id = 'GQIRKB7LVOONM7VW'
  2627. # device_id = 'ZDQWUSSWBEDI896T'
  2628. # device_id = '656DTOPRZDEALZ5X'
  2629. # device_id = 'N7ZXBITOSOGMYXQS'
  2630. # device_id = '1462a51f'
  2631. # device_id = '4TZDUGTOAIFMJVGU'
  2632. # device_id = 'GIOFIBRKZTUGJJAE'
  2633. # device_id = 'fcb3c749'
  2634. search_key_length = len(search_key_list)
  2635. for keyword_idx, search_key in enumerate(search_key_list):
  2636. print(f"正在处理第 {keyword_idx+1}/{len(search_key_list)} 个关键词:{search_key}")
  2637. pdd = PDD(search_key, device_id)
  2638. # pdd.unitest()
  2639. # pdd.main('369dcf96')
  2640. # pdd.main('2e58510')
  2641. pdd.main(device_id, search_key_length, keyword_idx)
  2642. if __name__ == '__main__':
  2643. main()
  2644. # scheduler = BlockingScheduler()
  2645. # scheduler.add_job(main, 'cron', hour=11, minute=1, misfire_grace_time=120)
  2646. # try:
  2647. # scheduler.start()
  2648. # except (KeyboardInterrupt, SystemExit):
  2649. # pass