资讯详情

资讯详情

影刀RPA深度实战:小红书完整自动化运营SOP与私信自动回复系统

影刀RPA深度实战小红书完整自动化运营SOP与私信自动回复系统作者林焱做小红书运营的人最花时间的事情不是写笔记而是「盯著评论区回复」「看到潜在客户主动私信」「把咨询数据整理到表格里」。我之前帮一个美妆品牌搭过一套完整的小红书自动化运营系统把这三个环节全部自动化了。这篇文章把整套SOP的完整实现方法写出来。一、完整SOP流程设计1.1 自动化运营的完整链路关键词搜索 → 筛选相关笔记 → 提取笔记数据 → 监控评论 → 识别潜在客户 ↓ 自动发送私信或人工审核后发送 ↓ 记录私信结果 → 回写飞书多维表格1.2 为什么需要「人工审核」环节直接全自动发私信很容易被小红书判定为营销号导致禁言或封号。正确的做法全自动搜索 → 筛选 → 提取数据 → 识别潜在客户 → 生成私信草稿 半自动人工审核私信草稿 → 点击「确认发送」→ 自动发送并记录二、关键词搜索与笔记筛选2.1 搜索关键词的策略不要把所有关键词堆在一个流程里跑。按「意图」把关键词分组关键词类型示例意图私信策略痛点类“痘痘怎么治”、“干皮用什么”有明确需求推荐产品优惠券对比类“A牌和B牌哪个好”在决策期发送对比测评求推荐类“求好用的xx推荐”高意向重点跟进快速私信2.2 搜索筛选的完整代码# -*- coding: utf-8 -*-# 功能小红书关键词搜索筛选相关笔记importrequestsimporttimeimportrandomfromlxmlimportetreedefsearch_xiaohongshu_notes(keywords,max_notes20): 搜索小红书笔记返回符合条件的笔记列表 :param keywords: 关键词列表如 [痘痘, 护肤] :param max_notes: 每个关键词最多采集多少篇笔记 :return: 笔记列表字典 all_notes[]headers{User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36,Referer:https://www.xiaohongshu.com/,# Cookie需要替换成你自己的Cookie:your_cookie_here,}forkeywordinkeywords:print(f\n 搜索关键词{keyword})notes[]# 小红书搜索结果页通常有1-3页就够了的forpageinrange(1,4):urlfhttps://www.xiaohongshu.com/search_result?keyword{keyword}sourceweb_search_result_notespage{page}try:# 随机延迟避免被限流time.sleep(random.uniform(3,5))resprequests.get(url,headersheaders,timeout15)ifresp.status_code!200:print(f 第{page}页请求失败状态码{resp.status_code})breakhtmletree.HTML(resp.text)# 提取笔记链接note_linkshtml.xpath(//a[contains(href, /explore/)]/href)forlinkinnote_links:iflen(notes)max_notes:breakfull_linklinkiflink.startswith(http)elsehttps://www.xiaohongshu.comlink# 去重ifnotany(n[url]full_linkforninnotes):notes.append({keyword:keyword,url:full_link,collected_at:time.strftime(%Y-%m-%d %H:%M:%S)})print(f 第{page}页获得{len(note_links)}条链接累计{len(notes)}条)iflen(notes)max_notes:breakexceptExceptionase:print(f 第{page}页采集异常{str(e)})break# 对笔记做初步筛选按互动量filtered_notesfilter_notes_by_engagement(notes,min_likes50)all_notes.extend(filtered_notes)print(f关键词「{keyword}」采集完成原始{len(notes)}条筛选后{len(filtered_notes)}条)returnall_notesdeffilter_notes_by_engagement(notes,min_likes50): 按互动量筛选笔记需要进入笔记详情页获取点赞数 这里先做URL层面的筛选详细筛选在进入详情页后做 # 初步筛选排除广告笔记URL里包含某些特征filtered[]fornoteinnotes:urlnote.get(url,)# 排除广告小红书广告笔记的URL有特殊参数ifadnotinurl.lower()andpromotionnotinurl.lower():filtered.append(note)returnfiltered三、提取笔记详情与评论3.1 笔记详情页的数据提取# -*- coding: utf-8 -*-# 功能提取小红书笔记详情页的数据defextract_note_detail(driver,note_url): 用浏览器模拟的方式提取笔记详情 :param driver: 影刀的浏览器对象 :param note_url: 笔记链接 :return: 笔记详情字典 driver.get(note_url)time.sleep(3)# 等待页面加载detail{url:note_url,title:,author:,likes:0,comments_count:0,content:,publish_time:}try:# 提取标题title_elemdriver.find_element_by_xpath(//div[classtitle])detail[title]title_elem.text.strip()except:print( 提取标题失败)try:# 提取作者author_elemdriver.find_element_by_xpath(//a[classauthor])detail[author]author_elem.text.strip()except:print( 提取作者失败)try:# 提取点赞数likes_elemdriver.find_element_by_xpath(//span[contains(class, like)])likes_textlikes_elem.text.strip().replace(点赞,).replace(万,0000)detail[likes]int(likes_text)iflikes_text.isdigit()else0except:pass# 点赞数提取失败不影响后续流程try:# 提取笔记正文content_elemdriver.find_element_by_xpath(//div[classcontent])detail[content]content_elem.text.strip()except:print( 提取正文失败)returndetail3.2 评论内容提取# -*- coding: utf-8 -*-# 功能提取小红书笔记的评论内容defextract_comments(driver,max_comments50): 提取当前笔记页的评论 :param driver: 影刀的浏览器对象 :param max_comments: 最多提取多少条评论 :return: 评论列表 comments[]# 先滚动页面让评论区加载出来driver.execute_script(window.scrollTo(0, document.body.scrollHeight/2);)time.sleep(2)# 点击「查看更多评论」按钮如果有try:load_more_btndriver.find_element_by_xpath(//span[contains(text(), 查看更多评论)])load_more_btn.click()time.sleep(2)except:pass# 没有「查看更多评论」按钮跳过# 提取评论comment_elemsdriver.find_elements_by_xpath(//div[classcomment-item])fori,eleminenumerate(comment_elems):ifimax_comments:breaktry:comment{author:,content:,time:,likes:0}comment[author]elem.find_element_by_xpath(.//a[classauthor]).text.strip()comment[content]elem.find_element_by_xpath(.//div[classcontent]).text.strip()comment[time]elem.find_element_by_xpath(.//span[classtime]).text.strip()try:likes_textelem.find_element_by_xpath(.//span[classlike-count]).text.strip()comment[likes]int(likes_text)iflikes_text.isdigit()else0except:passcomments.append(comment)exceptExceptionase:print(f 提取第{i1}条评论失败{str(e)})continueprint(f 提取到{len(comments)}条评论)returncomments四、潜在客户识别4.1 识别规则不是所有评论都需要私信。需要定义「潜在客户」的识别规则# -*- coding: utf-8 -*-# 功能识别评论中的潜在客户defidentify_potential_customers(comments,keywords_config): 识别潜在客户 :param comments: 评论列表 :param keywords_config: 关键词配置字典 :return: 潜在客户列表 potential[]# 高意向关键词直接表达需求high_intent_keywords[求推荐,哪里买,多少钱,怎么买,链接,店铺]# 中意向关键词表达痛点mid_intent_keywords[怎么办,有用吗,好用吗,适合,敏感肌,痘痘]forcommentincomments:contentcomment.get(content,).lower()# 计算意向分数score0matched_keywords[]forkwinhigh_intent_keywords:ifkwincontent:score10matched_keywords.append(kw)forkwinmid_intent_keywords:ifkwincontent:score5matched_keywords.append(kw)# 分数阈值10 为高意向5 为中意向ifscore5:potential.append({comment_author:comment.get(author,),comment_content:content,intent_score:score,intent_level:高ifscore10else中,matched_keywords:matched_keywords,comment_time:comment.get(time,)})# 去重同一个作者只保留分数最高的那条评论seen_authors{}forpinpotential:authorp[comment_author]ifauthornotinseen_authorsorp[intent_score]seen_authors[author][intent_score]:seen_authors[author]p resultlist(seen_authors.values())print(f识别到{len(result)}个潜在客户)returnresult五、私信自动回复系统5.1 私信内容模板管理# -*- coding: utf-8 -*-# 功能管理私信内容模板# 私信模板配置存储在JSON文件里方便修改PRIVATE_MESSAGE_TEMPLATES{high_intent:[你好看到你在笔记下的评论很高兴你对这个问题感兴趣我们有一份详细的解决方案方便的话可以发给你参考一下,Hi感谢你的关注关于你提到的这个问题我们整理了一份资料对你应该有帮助方便发给你吗],mid_intent:[你好呀看到你的评论很有共鸣这个问题我也遇到过后来找到了解决方法有兴趣的话可以交流一下]}defget_private_message_template(intent_level,customer_name): 根据意向等级获取私信模板并填充客户名称 :param intent_level: 意向等级高/中 :param customer_name: 客户名称用于个性化 :return: 填充后的私信内容 importrandom keyhigh_intentifintent_level高elsemid_intenttemplatesPRIVATE_MESSAGE_TEMPLATES.get(key,[])ifnottemplates:returnf你好{customer_name}感谢你的关注# 随机选一个模板避免发送的内容完全一样被系统识别为营销templaterandom.choice(templates)# 填充客户名称messagetemplate.replace(你,customer_name,1)ifcustomer_nameelsetemplatereturnmessage5.2 发送私信的完整流程# -*- coding: utf-8 -*-# 功能发送小红书私信defsend_xiaohongshu_private_message(driver,target_user,message): 发送小红书私信 :param driver: 影刀的浏览器对象 :param target_user: 目标用户名 :param message: 私信内容 :return: 是否发送成功 try:# 步骤1打开目标用户的主页user_homepagefhttps://www.xiaohongshu.com/user/profile/{target_user}driver.get(user_homepage)time.sleep(3)# 步骤2点击「发私信」按钮message_btndriver.find_element_by_xpath(//button[contains(text(), 发私信)])message_btn.click()time.sleep(2)# 步骤3在输入框里输入私信内容input_boxdriver.find_element_by_xpath(//textarea[placeholder说点什么...])input_box.send_keys(message)time.sleep(1)# 步骤4点击「发送」按钮send_btndriver.find_element_by_xpath(//button[contains(text(), 发送)])send_btn.click()time.sleep(2)print(f 私信发送成功{target_user})returnTrueexceptExceptionase:print(f 私信发送失败{target_user}错误{str(e)})returnFalsedefbatch_send_private_messages(driver,potential_customers,max_per_day20): 批量发送私信带频率控制避免被限流 :param driver: 影刀的浏览器对象 :param potential_customers: 潜在客户列表 :param max_per_day: 每天最多发送多少条私信避免被封 sent_count0forcustomerinpotential_customers:ifsent_countmax_per_day:print(f已达到每日发送上限{max_per_day}条停止发送)breakauthorcustomer.get(comment_author,)intent_levelcustomer.get(intent_level,中)# 生成私信内容messageget_private_message_template(intent_level,author)# 发送私信successsend_xiaohongshu_private_message(driver,author,message)ifsuccess:sent_count1# 记录发送结果写入飞书或本地文件log_private_message_result(customer,message,success)# 频率控制每条私信间隔30-60秒time.sleep(random.uniform(30,60))else:log_private_message_result(customer,message,failed)time.sleep(10)# 发送失败等待时间短一点继续发下一个print(f\n今日私信发送完成成功{sent_count}条)六、数据回写飞书多维表格6.1 数据结构设计在飞书多维表格里创建以下字段字段名类型说明笔记链接文本来源笔记的URL笔记标题文本笔记标题评论作者文本潜在客户的用户名评论内容文本原始评论内容意向等级单选高/中/低意向分数数字意向分数用于排序私信内容文本发送的私信内容发送状态单选待发送/已发送/发送失败发送时间日期私信发送时间跟进状态单选未跟进/已回复/已转化6.2 回写代码复用第二篇的飞书API代码# -*- coding: utf-8 -*-# 功能将潜在客户数据写入飞书多维表格defwrite_potential_customers_to_feishu(potential_customers,token,app_token,table_id): 将潜在客户数据写入飞书 :param potential_customers: 潜在客户列表 :param token: 飞书 Token :param app_token: 多维表格 App Token :param table_id: 数据表 ID records[]forcustomerinpotential_customers:record{fields:{笔记链接:customer.get(note_url,),笔记标题:customer.get(note_title,),评论作者:customer.get(comment_author,),评论内容:customer.get(comment_content,),意向等级:customer.get(intent_level,中),意向分数:customer.get(intent_score,0),私信内容:customer.get(private_message,),发送状态:待发送,发送时间:int(time.time()*1000),# 当前时间毫秒时间戳跟进状态:未跟进}}records.append(record)# 调用批量写入函数复用第二篇文章的代码successbatch_write_to_feishu(token,app_token,table_id,records)print(f潜在客户数据回写飞书完成成功{success}条)七、完整流程编排影刀指令序列【主流程小红书自动化运营SOP】 1. 【Python节点】- 加载关键词配置 输出keywords列表 2. 【Python节点】- 搜索笔记 筛选 调用search_xiaohongshu_notes(keywords) 输出notes_list列表 3. 【循环】- 遍历 notes_list 中的每个笔记 4. 【Python节点】- 提取笔记详情 调用extract_note_detail(driver, note_url) 输出note_detail对象 5. 【Python节点】- 提取评论 调用extract_comments(driver) 输出comments_list列表 6. 【Python节点】- 识别潜在客户 调用identify_potential_customers(comments_list) 输出potential_customers列表 7. 【条件判断】- 如果 potential_customers 长度 0 a. 【Python节点】- 生成私信内容 b. 【人工审核】- 弹出私信草稿等待用户确认或设成全自动 c. 【Python节点】- 批量发送私信 调用batch_send_private_messages(driver, potential_customers) 8. 【Python节点】- 数据回写飞书 调用write_potential_customers_to_feishu() 9. 【等待】- 随机延迟 10-20 秒避免操作过快 10.【循环结束】 11.【飞书通知】- 发送今日运营日报常见问题速查#现象原因解决方式1私信发送后账号被禁言发送频率过高被系统识别为营销控制发送频率每条间隔30秒以上每天不超过20条2评论提取不全评论区没有全部加载在提取评论前模拟滚动让评论区全部加载或点击「查看更多评论」3潜在客户识别不准确关键词匹配规则太简单用NLP做语义分析可用影刀Python节点调用百度NLP API4小红书页面元素捕获失败页面结构更新XPath失效用CSS选择器代替XPath或定期维护元素定位规则5Cookie频繁过期小红书登录态有效期短每天运行前手动检查Cookie是否有效失效则重新登录6私信内容被系统屏蔽内容包含敏感词如微信、二维码私信内容里不要直接放联系方式引导用户主动询问7数据回写飞书很慢逐条写入没有批量操作用batch_write_to_feishu()批量写入每次最多500条推荐资源小红书开放平台如有企业认证可申请APIhttps://open.xiaohongshu.com/影刀RPA浏览器自动化最佳实践https://academy.yingdao.com/飞书多维表格API文档https://open.feishu.cn/内容标签影刀RPA小红书自动化私信自动回复潜在客户识别评论采集运营SOP飞书多维表格批量私信营销自动化数据回写转载请注明出处飞行社社区作者林焱
觉得有用,分享给同行:

为您的企业打造数字门面

稳重轻奢商务风格,端正雅致视觉,长效耐看不易过时。

立即咨询 →