我是个地地道道的农民 發表於 2025-6-19 15:45:00

自动小红书发布笔记工具,小红书作品视频自动发布软件,易语言免费版下载

<p>下载地址:https://pan38.com/share.php?code=vAWwa   提取码:bilibili</p>
<p>源码部分:<br>
`<br>
import os<br>
import time<br>
import json<br>
import random<br>
from selenium import webdriver<br>
from selenium.webdriver.common.by import By<br>
from selenium.webdriver.support.ui import WebDriverWait<br>
from selenium.webdriver.support import expected_conditions as EC<br>
from selenium.webdriver.common.action_chains import ActionChains<br>
from selenium.webdriver.chrome.options import Options<br>
from PIL import Image<br>
import cv2<br>
import numpy as np</p>
<p>class XHSAutoPoster:<br>
def <strong>init</strong>(self):<br>
self.driver = None<br>
self.cookies_file = "xhs_cookies.json"<br>
self.config = {<br>
"headless": False,<br>
"proxy": None,<br>
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",<br>
"wait_time": 30,<br>
"implicit_wait": 10<br>
}</p>
<pre><code>def init_driver(self):
    chrome_options = Options()
    if self.config["headless"]:
      chrome_options.add_argument("--headless")
    if self.config["proxy"]:
      chrome_options.add_argument(f"--proxy-server={self.config['proxy']}")
   
    chrome_options.add_argument(f"user-agent={self.config['user_agent']}")
    chrome_options.add_argument("--disable-blink-features=AutomationControlled")
    chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
    chrome_options.add_experimental_option("useAutomationExtension", False)
   
    self.driver = webdriver.Chrome(options=chrome_options)
    self.driver.implicitly_wait(self.config["implicit_wait"])
   
def login(self, phone, password):
    self.driver.get("https://creator.xiaohongshu.com/login")
   
    # 输入手机号
    phone_input = WebDriverWait(self.driver, self.config["wait_time"]).until(
      EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入手机号']"))
    )
    self.slow_type(phone_input, phone)
   
    # 点击获取验证码
    get_code_btn = self.driver.find_element(By.XPATH, "//button")
    get_code_btn.click()
   
    # 等待用户输入验证码
    code = input("请输入收到的验证码: ")
    code_input = self.driver.find_element(By.XPATH, "//input[@placeholder='请输入验证码']")
    self.slow_type(code_input, code)
   
    # 点击登录
    login_btn = self.driver.find_element(By.XPATH, "//button")
    login_btn.click()
   
    # 保存cookies
    self.save_cookies()
   
def save_cookies(self):
    cookies = self.driver.get_cookies()
    with open(self.cookies_file, "w") as f:
      json.dump(cookies, f)
      
def load_cookies(self):
    if os.path.exists(self.cookies_file):
      with open(self.cookies_file, "r") as f:
            cookies = json.load(f)
            for cookie in cookies:
                self.driver.add_cookie(cookie)
      return True
    return False

def post_image_note(self, title, content, image_paths):
    self.driver.get("https://creator.xiaohongshu.com/publish/publish")
   
    # 输入标题
    title_input = WebDriverWait(self.driver, self.config["wait_time"]).until(
      EC.presence_of_element_located((By.XPATH, "//textarea[@placeholder='填写标题']"))
    )
    self.slow_type(title_input, title)
   
    # 输入内容
    content_div = self.driver.find_element(By.XPATH, "//div[@class='editor']")
    content_div.click()
    self.slow_type(content_div, content)
   
    # 上传图片
    for img_path in image_paths:
      file_input = self.driver.find_element(By.XPATH, "//input[@type='file']")
      file_input.send_keys(os.path.abspath(img_path))
      time.sleep(3)# 等待上传完成
      
    # 点击发布
    publish_btn = WebDriverWait(self.driver, self.config["wait_time"]).until(
      EC.element_to_be_clickable((By.XPATH, "//button"))
    )
    publish_btn.click()
   
    return True

def post_video_note(self, title, content, video_path, cover_path=None):
    self.driver.get("https://creator.xiaohongshu.com/publish/publish?type=video")
   
    # 上传视频
    file_input = WebDriverWait(self.driver, self.config["wait_time"]).until(
      EC.presence_of_element_located((By.XPATH, "//input[@type='file']"))
    )
    file_input.send_keys(os.path.abspath(video_path))
   
    # 监控上传进度
    while True:
      try:
            progress = self.driver.find_element(By.XPATH, "//div")
            if "100%" in progress.text:
                break
            time.sleep(2)
      except:
            break
            
    # 输入标题
    title_input = WebDriverWait(self.driver, self.config["wait_time"]).until(
      EC.presence_of_element_located((By.XPATH, "//textarea[@placeholder='填写标题']"))
    )
    self.slow_type(title_input, title)
   
    # 输入内容
    content_div = self.driver.find_element(By.XPATH, "//div[@class='editor']")
    content_div.click()
    self.slow_type(content_div, content)
   
    # 等待转码完成
    time.sleep(30)
   
    # 点击发布
    publish_btn = WebDriverWait(self.driver, self.config["wait_time"]).until(
      EC.element_to_be_clickable((By.XPATH, "//button"))
    )
    publish_btn.click()
   
    return True

def slow_type(self, element, text, delay=0.1):
    for character in text:
      element.send_keys(character)
      time.sleep(random.uniform(delay/2, delay*1.5))
      
def human_like_scroll(self):
    for _ in range(random.randint(2, 5)):
      scroll_px = random.randint(200, 800)
      self.driver.execute_script(f"window.scrollBy(0, {scroll_px})")
      time.sleep(random.uniform(0.5, 2.0))
      
def close(self):
    if self.driver:
      self.driver.quit()
      
def __del__(self):
    self.close()
</code></pre>
<p>if <strong>name</strong> == "<strong>main</strong>":<br>
poster = XHSAutoPoster()<br>
poster.init_driver()</p>
<pre><code># 尝试加载cookies
if not poster.load_cookies():
    # 需要登录
    poster.login("your_phone_number", "your_password")

# 发布图文笔记示例
poster.post_image_note(
    "测试自动发布图文笔记",
    "这是通过Python脚本自动发布的小红书图文笔记内容 #自动化 #小红书运营",
    ["image1.jpg", "image2.jpg"]
)

# 发布视频笔记示例
poster.post_video_note(
    "测试自动发布视频笔记",
    "这是通过Python脚本自动发布的小红书视频笔记内容 #视频 #自动化",
    "test_video.mp4"
)

poster.close()
</code></pre>
<p>`</p><br><br>
来源:https://www.cnblogs.com/qianqian3378/p/18936635
頁: [1]
查看完整版本: 自动小红书发布笔记工具,小红书作品视频自动发布软件,易语言免费版下载