影刀RPA深度实战:小红书完整自动化运营SOP与私信自动回复系统
作者:林焱
做小红书运营的人最花时间的事情不是写笔记,而是「盯著评论区回复」「看到潜在客户主动私信」「把咨询数据整理到表格里」。我之前帮一个美妆品牌搭过一套完整的小红书自动化运营系统,把这三个环节全部自动化了。这篇文章把整套SOP的完整实现方法写出来。
一、完整SOP流程设计
1.1 自动化运营的完整链路
关键词搜索 → 筛选相关笔记 → 提取笔记数据 → 监控评论 → 识别潜在客户 ↓ 自动发送私信(或人工审核后发送) ↓ 记录私信结果 → 回写飞书多维表格1.2 为什么需要「人工审核」环节?
直接全自动发私信,很容易被小红书判定为营销号,导致禁言或封号。正确的做法:
全自动:搜索 → 筛选 → 提取数据 → 识别潜在客户 → 生成私信草稿 半自动:人工审核私信草稿 → 点击「确认发送」→ 自动发送并记录二、关键词搜索与笔记筛选
2.1 搜索关键词的策略
不要把所有关键词堆在一个流程里跑。按「意图」把关键词分组:
| 关键词类型 | 示例 | 意图 | 私信策略 |
|---|---|---|---|
| 痛点类 | “痘痘怎么治”、“干皮用什么” | 有明确需求 | 推荐产品+优惠券 |
| 对比类 | “A牌和B牌哪个好” | 在决策期 | 发送对比测评 |
| 求推荐类 | “求好用的xx推荐” | 高意向 | 重点跟进,快速私信 |
2.2 搜索+筛选的完整代码
# -*- coding: utf-8 -*-# 功能:小红书关键词搜索,筛选相关笔记importrequestsimporttimeimportrandomfromlxmlimportetreedefsearch_xiaohongshu_notes(keywords,max_notes=20):""" 搜索小红书笔记,返回符合条件的笔记列表 :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):url=f'https://www.xiaohongshu.com/search_result?keyword={keyword}&source=web_search_result_notes&page={page}'try:# 随机延迟,避免被限流time.sleep(random.uniform(3,5))resp=requests.get(url,headers=headers,timeout=15)ifresp.status_code!=200:print(f' 第{page}页请求失败,状态码:{resp.status_code}')breakhtml=etree.HTML(resp.text)# 提取笔记链接note_links=html.xpath('//a[contains(@href, "/explore/")]/@href')forlinkinnote_links:iflen(notes)>=max_notes:breakfull_link=linkiflink.startswith('http')else'https://www.xiaohongshu.com'+link# 去重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_notes=filter_notes_by_engagement(notes,min_likes=50)all_notes.extend(filtered_notes)print(f'关键词「{keyword}」采集完成:原始{len(notes)}条,筛选后{len(filtered_notes)}条')returnall_notesdeffilter_notes_by_engagement(notes,min_likes=50):""" 按互动量筛选笔记(需要进入笔记详情页获取点赞数) 这里先做URL层面的筛选,详细筛选在进入详情页后做 """# 初步筛选:排除广告笔记(URL里包含某些特征)filtered=[]fornoteinnotes:url=note.get('url','')# 排除广告(小红书广告笔记的URL有特殊参数)if'ad'notinurl.lower()and'promotion'notinurl.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_elem=driver.find_element_by_xpath('//div[@class="title"]')detail['title']=title_elem.text.strip()except:print(' 提取标题失败')try:# 提取作者author_elem=driver.find_element_by_xpath('//a[@class="author"]')detail['author']=author_elem.text.strip()except:print(' 提取作者失败')try:# 提取点赞数likes_elem=driver.find_element_by_xpath('//span[contains(@class, "like")]')likes_text=likes_elem.text.strip().replace('点赞','').replace('万','0000')detail['likes']=int(likes_text)iflikes_text.isdigit()else0except:pass# 点赞数提取失败不影响后续流程try:# 提取笔记正文content_elem=driver.find_element_by_xpath('//div[@class="content"]')detail['content']=content_elem.text.strip()except:print(' 提取正文失败')returndetail3.2 评论内容提取
# -*- coding: utf-8 -*-# 功能:提取小红书笔记的评论内容defextract_comments(driver,max_comments=50):""" 提取当前笔记页的评论 :param driver: 影刀的浏览器对象 :param max_comments: 最多提取多少条评论 :return: 评论列表 """comments=[]# 先滚动页面,让评论区加载出来driver.execute_script('window.scrollTo(0, document.body.scrollHeight/2);')time.sleep(2)# 点击「查看更多评论」按钮(如果有)try:load_more_btn=driver.find_element_by_xpath('//span[contains(text(), "查看更多评论")]')load_more_btn.click()time.sleep(2)except:pass# 没有「查看更多评论」按钮,跳过# 提取评论comment_elems=driver.find_elements_by_xpath('//div[@class="comment-item"]')fori,eleminenumerate(comment_elems):ifi>=max_comments:breaktry:comment={'author':'','content':'','time':'','likes':0}comment['author']=elem.find_element_by_xpath('.//a[@class="author"]').text.strip()comment['content']=elem.find_element_by_xpath('.//div[@class="content"]').text.strip()comment['time']=elem.find_element_by_xpath('.//span[@class="time"]').text.strip()try:likes_text=elem.find_element_by_xpath('.//span[@class="like-count"]').text.strip()comment['likes']=int(likes_text)iflikes_text.isdigit()else0except:passcomments.append(comment)exceptExceptionase:print(f' 提取第{i+1}条评论失败:{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:content=comment.get('content','').lower()# 计算意向分数score=0matched_keywords=[]forkwinhigh_intent_keywords:ifkwincontent:score+=10matched_keywords.append(kw)forkwinmid_intent_keywords:ifkwincontent:score+=5matched_keywords.append(kw)# 分数阈值:>=10 为高意向,>=5 为中意向ifscore>=5:potential.append({'comment_author':comment.get('author',''),'comment_content':content,'intent_score':score,'intent_level':'高'ifscore>=10else'中','matched_keywords':matched_keywords,'comment_time':comment.get('time','')})# 去重(同一个作者只保留分数最高的那条评论)seen_authors={}forpinpotential:author=p['comment_author']ifauthornotinseen_authorsorp['intent_score']>seen_authors[author]['intent_score']:seen_authors[author]=p result=list(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 key='high_intent'ifintent_level=='高'else'mid_intent'templates=PRIVATE_MESSAGE_TEMPLATES.get(key,[])ifnottemplates:returnf'你好{customer_name},感谢你的关注!'# 随机选一个模板(避免发送的内容完全一样,被系统识别为营销)template=random.choice(templates)# 填充客户名称message=template.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_homepage=f'https://www.xiaohongshu.com/user/profile/{target_user}'driver.get(user_homepage)time.sleep(3)# 步骤2:点击「发私信」按钮message_btn=driver.find_element_by_xpath('//button[contains(text(), "发私信")]')message_btn.click()time.sleep(2)# 步骤3:在输入框里输入私信内容input_box=driver.find_element_by_xpath('//textarea[@placeholder="说点什么..."]')input_box.send_keys(message)time.sleep(1)# 步骤4:点击「发送」按钮send_btn=driver.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_day=20):""" 批量发送私信(带频率控制,避免被限流) :param driver: 影刀的浏览器对象 :param potential_customers: 潜在客户列表 :param max_per_day: 每天最多发送多少条私信(避免被封) """sent_count=0forcustomerinpotential_customers:ifsent_count>=max_per_day:print(f'已达到每日发送上限({max_per_day}条),停止发送')breakauthor=customer.get('comment_author','')intent_level=customer.get('intent_level','中')# 生成私信内容message=get_private_message_template(intent_level,author)# 发送私信success=send_xiaohongshu_private_message(driver,author,message)ifsuccess:sent_count+=1# 记录发送结果(写入飞书或本地文件)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)# 调用批量写入函数(复用第二篇文章的代码)success=batch_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 API) |
| 4 | 小红书页面元素捕获失败 | 页面结构更新,XPath失效 | 用CSS选择器代替XPath,或定期维护元素定位规则 |
| 5 | Cookie频繁过期 | 小红书登录态有效期短 | 每天运行前手动检查Cookie是否有效,失效则重新登录 |
| 6 | 私信内容被系统屏蔽 | 内容包含敏感词(如微信、二维码) | 私信内容里不要直接放联系方式,引导用户主动询问 |
| 7 | 数据回写飞书很慢 | 逐条写入,没有批量操作 | 用batch_write_to_feishu()批量写入,每次最多500条 |
推荐资源
- 小红书开放平台(如有企业认证可申请API):https://open.xiaohongshu.com/
- 影刀RPA浏览器自动化最佳实践:https://academy.yingdao.com/
- 飞书多维表格API文档:https://open.feishu.cn/
内容标签
影刀RPA小红书自动化私信自动回复潜在客户识别评论采集运营SOP飞书多维表格批量私信营销自动化数据回写
转载请注明出处:飞行社社区,作者:林焱