影刀RPA 医药行业自动化:药品信息采集与价格监控
影刀RPA 医药行业自动化:药品信息采集与价格监控
作者:林焱
一、什么情况用影刀处理医药数据
医药行业的信息管理痛点很明显:国家医保局每季度更新医保目录,各省市的药品挂网价格频繁调整,药企的市场部门需要实时掌握竞品价格动向。靠人工每天登各个系统查价格,完全来不及,而且容易遗漏。
典型场景:
- 监控国家医保局网站的政策更新,第一时间通知医保事务团队
- 采集各省市挂网平台的药品价格,对比分析市场价格趋势
- 从医药企业官网批量采集竞品说明书信息
二、实战一:医保政策更新监控
importhashlibimportrequests# 监控国家医保局网站target_pages=[{'name':'医保目录调整公告','url':'https://www.nhsa.gov.cn/col/col452/index.html','selector':'.news-list'},{'name':'药品挂网价格通知','url':'https://www.nhsa.gov.cn/col/col457/index.html','selector':'.news-list'}]saved_hashes={}# 实际应存储到文件中持久化forpageintarget_pages:yingdao.open_url(page['url'])yingdao.wait_for_element(page['selector'])content=yingdao.find_element(page['selector']).text current_hash=hashlib.md5(content.encode('utf-8')).hexdigest()last_hash=saved_hashes.get(page['name'],'')ifcurrent_hash!=last_hash:# 提取新增内容items=yingdao.find_elements(f"{page['selector']}li")latest=items[0].textifitemselse'无内容'# 发送通知yingdao.send_dingtalk_message(f"📋 医保政策更新提醒\n"f"栏目:{page['name']}\n"f"最新内容:{latest[:100]}...\n"f"链接:{page['url']}",group='医保事务群')saved_hashes[page['name']]=current_hashprint(f"✅{page['name']}已更新")三、实战二:各省挂网价格批量采集
不同省市有不同的药品挂网采购平台,医药代表需要定期比对同一药品在各省的挂网价格。
# 以某省阳光采购平台为例target_drugs=['阿莫西林胶囊','布洛芬片','二甲双胍缓释片']# 各省平台配置platforms=[{'province':'浙江','url':'https://www.zjyp.com.cn/search','search_id':'#search-input'},{'province':'广东','url':'https://www.gdyp.gov.cn/search','search_id':'.search-box'},# 更多省份...]price_data=[]forplatforminplatforms:fordrug_nameintarget_drugs:yingdao.open_url(platform['url'])yingdao.wait_for_element(platform['search_id'])yingdao.find_element(platform['search_id']).send_keys(drug_name)yingdao.find_element('.search-submit').click()yingdao.wait_for_element('.result-list',timeout=15)# 采集搜索结果results=yingdao.find_elements('.result-item')forresultinresults[:5]:# 只取前5条try:name=result.find_element('.drug-name').text spec=result.find_element('.specification').text manufacturer=result.find_element('.manufacturer').text price=result.find_element('.price').text price_data.append({'省份':platform['province'],'药品名称':name,'规格':spec,'生产企业':manufacturer,'挂网价(元)':price,'采集日期':today})exceptException:continueyingdao.wait(1.5)df=pd.DataFrame(price_data)df.to_excel(f'C:\\医药\\价格数据_{today}.xlsx',index=False)生成价格对比分析:
# 同一药品在不同省份的价格对比pivot=df.pivot_table(index=['药品名称','规格','生产企业'],columns='省份',values='挂网价(元)',aggfunc='first')# 计算省间价差pivot['最高价']=pivot.max(axis=1)pivot['最低价']=pivot.min(axis=1)pivot['价差率']=((pivot['最高价']-pivot['最低价'])/pivot['最低价']*100).round(1)# 标记价差超过20%的药品high_variance=pivot[pivot['价差率']>20]print(f"发现{len(high_variance)}个药品省间价差超过20%")四、实战三:说明书信息批量提取
药企做竞品分析,需要采集竞品说明书中的适应症、用法用量、不良反应等信息。
# 从药智网或丁香园采集说明书drug_list=['阿奇霉素分散片','左氧氟沙星注射液','头孢克肟胶囊']inserts=[]fordrugindrug_list:yingdao.open_url(f'https://db.yaozh.com/instructions?keyword={drug}')yingdao.wait_for_element('.insert-list')first_item=yingdao.find_element('.insert-item:first-child a')first_item.click()yingdao.wait_for_element('.insert-content')sections={'适应症':'.section-indications','用法用量':'.section-dosage','不良反应':'.section-adr','禁忌':'.section-contraindication',}insert_data={'药品名称':drug}forsection_name,selectorinsections.items():try:insert_data[section_name]=yingdao.find_element(selector).text[:500]except:insert_data[section_name]='未获取到'inserts.append(insert_data)yingdao.wait(2)pd.DataFrame(inserts).to_excel('竞品说明书对比.xlsx',index=False)五、踩坑记录
坑1:各省平台结构差异大
30个省市有30种不同的采购平台,很难写一套通用代码。建议用配置文件管理各省平台的URL和选择器,每省单独维护。
坑2:价格数据中有"暂停供应"等非数字内容
价格列要处理非数字值:
df['挂网价_数值']=pd.to_numeric(df['挂网价(元)'].str.replace('[^\d.]','',regex=True),errors='coerce')坑3:医保局网站访问速度慢
政府网站服务器性能有限,设置timeout=30并增加重试机制,而不是等待超时报错。
坑4:说明书文本提取后需要清洗
OCR或直接抓取的说明书文本含有大量换行符、空格,用正则预处理:
text=re.sub(r'\s+',' ',text).strip()适用人群:医药代表、医保事务专员、市场准入团队
难度:⭐⭐⭐(需要了解医药行业平台结构)
