get_app_pdd__data_3.py 146 KB

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