
影刀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])contentyingdao.find_element(page[selector]).text current_hashhashlib.md5(content.encode(utf-8)).hexdigest()last_hashsaved_hashes.get(page[name],)ifcurrent_hash!last_hash:# 提取新增内容itemsyingdao.find_elements(f{page[selector]}li)latestitems[0].textifitemselse无内容# 发送通知yingdao.send_dingtalk_message(f 医保政策更新提醒\nf栏目{page[name]}\nf最新内容{latest[:100]}...\nf链接{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,timeout15)# 采集搜索结果resultsyingdao.find_elements(.result-item)forresultinresults[:5]:# 只取前5条try:nameresult.find_element(.drug-name).text specresult.find_element(.specification).text manufacturerresult.find_element(.manufacturer).text priceresult.find_element(.price).text price_data.append({省份:platform[province],药品名称:name,规格:spec,生产企业:manufacturer,挂网价元:price,采集日期:today})exceptException:continueyingdao.wait(1.5)dfpd.DataFrame(price_data)df.to_excel(fC:\\医药\\价格数据_{today}.xlsx,indexFalse)生成价格对比分析# 同一药品在不同省份的价格对比pivotdf.pivot_table(index[药品名称,规格,生产企业],columns省份,values挂网价元,aggfuncfirst)# 计算省间价差pivot[最高价]pivot.max(axis1)pivot[最低价]pivot.min(axis1)pivot[价差率]((pivot[最高价]-pivot[最低价])/pivot[最低价]*100).round(1)# 标记价差超过20%的药品high_variancepivot[pivot[价差率]20]print(f发现{len(high_variance)}个药品省间价差超过20%)四、实战三说明书信息批量提取药企做竞品分析需要采集竞品说明书中的适应症、用法用量、不良反应等信息。# 从药智网或丁香园采集说明书drug_list[阿奇霉素分散片,左氧氟沙星注射液,头孢克肟胶囊]inserts[]fordrugindrug_list:yingdao.open_url(fhttps://db.yaozh.com/instructions?keyword{drug})yingdao.wait_for_element(.insert-list)first_itemyingdao.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,indexFalse)五、踩坑记录坑1各省平台结构差异大30个省市有30种不同的采购平台很难写一套通用代码。建议用配置文件管理各省平台的URL和选择器每省单独维护。坑2价格数据中有暂停供应等非数字内容价格列要处理非数字值df[挂网价_数值]pd.to_numeric(df[挂网价元].str.replace([^\d.],,regexTrue),errorscoerce)坑3医保局网站访问速度慢政府网站服务器性能有限设置timeout30并增加重试机制而不是等待超时报错。坑4说明书文本提取后需要清洗OCR或直接抓取的说明书文本含有大量换行符、空格用正则预处理textre.sub(r\s, ,text).strip()适用人群医药代表、医保事务专员、市场准入团队难度⭐⭐⭐需要了解医药行业平台结构