﻿{"id":4005,"date":"2026-04-03T14:37:51","date_gmt":"2026-04-03T06:37:51","guid":{"rendered":"http:\/\/www.jiayus.com\/?p=4005"},"modified":"2026-04-03T14:37:51","modified_gmt":"2026-04-03T06:37:51","slug":"%e8%88%86%e6%83%85%e7%9b%91%e6%b5%8b%e5%ae%9e%e6%88%98%ef%bc%9a%e5%a6%82%e4%bd%95%e5%90%88%e8%a7%84%e9%87%87%e9%9b%86%e5%b0%8f%e7%ba%a2%e4%b9%a6%e6%95%b0%e6%8d%ae%e6%9e%84%e5%bb%ba%e5%93%81%e7%89%8c","status":"publish","type":"post","link":"http:\/\/www.jiayus.com\/?p=4005","title":{"rendered":"\u8206\u60c5\u76d1\u6d4b\u5b9e\u6218\uff1a\u5982\u4f55\u5408\u89c4\u91c7\u96c6\u5c0f\u7ea2\u4e66\u6570\u636e\u6784\u5efa\u54c1\u724c\u53e3\u7891\u5206\u6790\u4f53\u7cfb"},"content":{"rendered":"<p>\u5728\u5f53\u4eca\u6570\u5b57\u5316\u8425\u9500\u65f6\u4ee3\uff0c\u5c0f\u7ea2\u4e66\u5df2\u6210\u4e3a\u54c1\u724c\u53e3\u7891\u4f20\u64ad\u7684\u6838\u5fc3\u9635\u5730\u3002\u6bcf\u5929\u6709\u6570\u767e\u4e07\u7528\u6237\u5728\u5e73\u53f0\u4e0a\u5206\u4eab\u6d88\u8d39\u4f53\u9a8c\u3001\u4ea7\u54c1\u6d4b\u8bc4\u548c\u751f\u6d3b\u65b9\u5f0f\u5185\u5bb9\uff0c\u8fd9\u4e9b\u6570\u636e\u5bf9\u4e8e\u4f01\u4e1a\u8206\u60c5\u76d1\u6d4b\u548c\u5e02\u573a\u7814\u7a76\u5177\u6709\u6781\u9ad8\u7684\u4ef7\u503c\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5408\u89c4\u91c7\u96c6\u5c0f\u7ea2\u4e66\u6570\u636e\uff0c\u6784\u5efa\u5b8c\u5584\u7684\u54c1\u724c\u53e3\u7891\u5206\u6790\u4f53\u7cfb\u3002<\/p>\n<h2>\u4e00\u3001\u5c0f\u7ea2\u4e66\u6570\u636e\u5728\u8206\u60c5\u76d1\u6d4b\u4e2d\u7684\u4ef7\u503c<\/h2>\n<p>\u5c0f\u7ea2\u4e66\uff08Xiaohongshu\uff09\u4f5c\u4e3a\u56fd\u5185\u9886\u5148\u7684\u751f\u6d3b\u65b9\u5f0f\u5206\u4eab\u5e73\u53f0\uff0c\u5176\u7528\u6237\u7fa4\u4f53\u4ee5\u4e00\u4e8c\u7ebf\u57ce\u5e02\u7684\u5e74\u8f7b\u5973\u6027\u4e3a\u4e3b\uff0c\u6d88\u8d39\u80fd\u529b\u5f3a\uff0c\u5185\u5bb9\u6d3b\u8dc3\u5ea6\u9ad8\u3002\u5e73\u53f0\u4e0a\u7684\u7b14\u8bb0\u5185\u5bb9\u6db5\u76d6\u7f8e\u5986\u62a4\u80a4\u3001\u7a7f\u642d\u65f6\u5c1a\u3001\u6bcd\u5a74\u80b2\u513f\u3001\u65c5\u884c\u51fa\u6e38\u3001\u9910\u996e\u7f8e\u98df\u7b49\u591a\u4e2a\u9886\u57df\uff0c\u5df2\u6210\u4e3a\u6d88\u8d39\u8005\u51b3\u7b56\u7684\u91cd\u8981\u53c2\u8003\u6765\u6e90\u3002<\/p>\n<p>\u5bf9\u4e8e\u4f01\u4e1a\u800c\u8a00\uff0c\u5c0f\u7ea2\u4e66\u6570\u636e\u76d1\u6d4b\u5177\u6709\u4ee5\u4e0b\u6838\u5fc3\u4ef7\u503c\uff1a<\/p>\n<p><strong>1. \u53e3\u7891\u9884\u8b66<\/strong>\uff1a\u901a\u8fc7\u76d1\u6d4b\u54c1\u724c\u76f8\u5173\u7b14\u8bb0\uff0c\u4f01\u4e1a\u53ef\u4ee5\u7b2c\u4e00\u65f6\u95f4\u53d1\u73b0\u8d1f\u9762\u8206\u60c5\uff0c\u53ca\u65f6\u54cd\u5e94\u5904\u7406\uff0c\u907f\u514d\u5371\u673a\u6269\u6563\u3002<\/p>\n<p><strong>2. \u7ade\u54c1\u5206\u6790<\/strong>\uff1a\u8ffd\u8e2a\u7ade\u54c1\u5728\u5c0f\u7ea2\u4e66\u4e0a\u7684\u58f0\u91cf\u3001\u5185\u5bb9\u7c7b\u578b\u3001\u7528\u6237\u53cd\u9988\uff0c\u4e3a\u5236\u5b9a\u8425\u9500\u7b56\u7565\u63d0\u4f9b\u6570\u636e\u652f\u6491\u3002<\/p>\n<p><strong>3. KOL\u7b5b\u9009<\/strong>\uff1a\u901a\u8fc7\u6570\u636e\u5206\u6790\u8bc6\u522b\u9ad8\u6027\u4ef7\u6bd4\u7684\u8170\u90e8\u535a\u4e3b\u548c\u7d20\u4eba\u7528\u6237\uff0c\u6784\u5efa\u9ad8\u6548\u7684\u79cd\u8349\u77e9\u9635\u3002<\/p>\n<p><strong>4. \u8d8b\u52bf\u6d1e\u5bdf<\/strong>\uff1a\u5206\u6790\u70ed\u95e8\u8bdd\u9898\u548c\u5185\u5bb9\u8d8b\u52bf\uff0c\u628a\u63e1\u5e02\u573a\u98ce\u5411\uff0c\u6307\u5bfc\u4ea7\u54c1\u7814\u53d1\u548c\u8425\u9500\u7b56\u5212\u3002<\/p>\n<h2>\u4e8c\u3001\u5c0f\u7ea2\u4e66\u6570\u636e\u91c7\u96c6\u7684\u6280\u672f\u539f\u7406<\/h2>\n<p>\u5c0f\u7ea2\u4e66\u91c7\u7528\u4e86\u591a\u79cd\u53cd\u722c\u866b\u6280\u672f\u6765\u4fdd\u62a4\u5e73\u53f0\u6570\u636e\u5b89\u5168\uff0c\u5305\u62ec\u53c2\u6570\u7b7e\u540d\u9a8c\u8bc1\u3001\u8bf7\u6c42\u9891\u7387\u9650\u5236\u3001UA\u68c0\u6d4b\u3001IP\u9650\u5236\u7b49\u3002\u5408\u89c4\u7684\u6570\u636e\u91c7\u96c6\u9700\u8981\u5728\u9075\u5b88\u5e73\u53f0\u89c4\u5219\u7684\u524d\u63d0\u4e0b\u8fdb\u884c\uff0c\u4ee5\u4e0b\u4ecb\u7ecd\u51e0\u79cd\u5e38\u89c1\u7684\u6280\u672f\u65b9\u6848\u3002<\/p>\n<h3>2.1 \u57fa\u4e8e\u5b98\u65b9API\u7684\u6570\u636e\u83b7\u53d6<\/h3>\n<p>\u5c0f\u7ea2\u4e66\u5f00\u653e\u4e86\u90e8\u5206API\u63a5\u53e3\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u7533\u8bf7\u63a5\u53e3\u6743\u9650\u83b7\u53d6\u6570\u636e\u3002\u8fd9\u79cd\u65b9\u5f0f\u6700\u4e3a\u5408\u89c4\uff0c\u6570\u636e\u8d28\u91cf\u4e5f\u6700\u9ad8\u3002<\/p>\n<pre><code>import requests\nimport json\nimport time\nimport hashlib\nimport random\n\nclass XiaohongshuAPI:\n    \"\"\"\u5c0f\u7ea2\u4e66\u5b98\u65b9API\u8c03\u7528\u5c01\u88c5\"\"\"\n    def __init__(self, app_id, app_secret):\n        self.app_id = app_id\n        self.app_secret = app_secret\n        self.access_token = None\n        self.token_expires_at = 0\n\n    def get_access_token(self):\n        if self.access_token and time.time() < self.token_expires_at:\n            return self.access_token\n        url = \"https:\/\/open.xiaohongshu.com\/oauth\/access_token\"\n        params = {\n            \"app_id\": self.app_id,\n            \"app_secret\": self.app_secret,\n            \"grant_type\": \"client_credential\"\n        }\n        response = requests.post(url, data=params, timeout=10)\n        result = response.json()\n        if result.get(\"code\") == 0:\n            self.access_token = result[\"data\"][\"access_token\"]\n            self.token_expires_at = time.time() + result[\"data\"][\"expires_in\"] - 300\n            return self.access_token\n        else:\n            raise Exception(f\"\u83b7\u53d6Token\u5931\u8d25: {result}\")\n\n    def search_notes(self, keyword, page=1, page_size=20):\n        url = \"https:\/\/open.xiaohongshu.com\/api\/notes\/search\"\n        headers = {\n            \"Authorization\": f\"Bearer {self.get_access_token()}\",\n            \"Content-Type\": \"application\/json\"\n        }\n        payload = {\"keyword\": keyword, \"page\": page, \"page_size\": page_size, \"sort\": \"general\"}\n        response = requests.post(url, headers=headers, json=payload, timeout=10)\n        return response.json()\n\n    def get_note_detail(self, note_id):\n        url = f\"https:\/\/open.xiaohongshu.com\/api\/notes\/{note_id}\"\n        headers = {\"Authorization\": f\"Bearer {self.get_access_token()}\"}\n        return requests.get(url, headers=headers, timeout=10).json()\n\n    def get_user_notes(self, user_id, page=1):\n        url = f\"https:\/\/open.xiaohongshu.com\/api\/users\/{user_id}\/notes\"\n        headers = {\"Authorization\": f\"Bearer {self.get_access_token()}\"}\n        params = {\"page\": page, \"page_size\": 20}\n        return requests.get(url, headers=headers, params=params, timeout=10).json()\n\nif __name__ == \"__main__\":\n    api = XiaohongshuAPI(app_id=\"YOUR_APP_ID\", app_secret=\"YOUR_APP_SECRET\")\n    search_result = api.search_notes(keyword=\"\u65b0\u80fd\u6e90\u6c7d\u8f66\", page=1)\n    print(f\"\u641c\u7d22\u5230 {search_result['data']['total']} \u7bc7\u7b14\u8bb0\")\n    for note in search_result['data']['notes'][:5]:\n        print(f\"\u6807\u9898: {note['title']}, \u70b9\u8d5e: {note['liked_count']}\")\n<\/code><\/pre>\n<h3>2.2 \u57fa\u4e8eSelenium\u7684\u6a21\u62df\u6d4f\u89c8\u5668\u91c7\u96c6<\/h3>\n<p>\u5bf9\u4e8e\u9700\u8981\u6a21\u62df\u767b\u5f55\u6216\u590d\u6742\u4ea4\u4e92\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u4f7f\u7528Selenium\u6a21\u62df\u771f\u5b9e\u6d4f\u89c8\u5668\u64cd\u4f5c\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u7ed5\u8fc7\u90e8\u5206\u53cd\u722c\u866b\u68c0\u6d4b\uff0c\u4f46\u9700\u8981\u63a7\u5236\u8bf7\u6c42\u9891\u7387\u3002<\/p>\n<pre><code>from selenium import webdriver\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.support import expected_conditions as EC\nfrom selenium.webdriver.chrome.options import Options\nfrom bs4 import BeautifulSoup\nimport time\nimport random\n\nclass XiaohongshuCrawler:\n    \"\"\"\u57fa\u4e8eSelenium\u7684\u5c0f\u7ea2\u4e66\u6570\u636e\u91c7\u96c6\u5668\"\"\"\n    def __init__(self, headless=True):\n        chrome_options = Options()\n        if headless:\n            chrome_options.add_argument(\"--headless\")\n        chrome_options.add_argument(\"--no-sandbox\")\n        chrome_options.add_argument(\"--disable-dev-shm-usage\")\n        chrome_options.add_argument(\"--disable-gpu\")\n        chrome_options.add_argument(\"--window-size=1920,1080\")\n        user_agent = \"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 Chrome\/120.0.0.0 Safari\/537.36\"\n        chrome_options.add_argument(f\"user-agent={user_agent}\")\n        chrome_options.add_experimental_option(\"excludeSwitches\", [\"enable-automation\"])\n        self.driver = webdriver.Chrome(options=chrome_options)\n        self.driver.execute_cdp_cmd(\"Page.addScriptToEvaluateOnNewDocument\", {\n            \"source\": \"Object.defineProperty(navigator, 'webdriver', {get: () => undefined});\"\n        })\n\n    def wait_random(self, min_sec=1, max_sec=3):\n        time.sleep(random.uniform(min_sec, max_sec))\n\n    def scroll_page(self, scroll_count=3):\n        for _ in range(scroll_count):\n            self.driver.execute_script(\"window.scrollTo(0, document.body.scrollHeight);\")\n            self.wait_random(1, 2)\n            self.driver.execute_script(\"window.scrollBy(0, -200);\")\n            self.wait_random(0.5, 1)\n\n    def search(self, keyword, max_notes=50):\n        search_url = f\"https:\/\/www.xiaohongshu.com\/search_result?keyword={keyword}&type=51\"\n        self.driver.get(search_url)\n        self.wait_random(2, 4)\n        notes = []\n        last_height = self.driver.execute_script(\"return document.body.scrollHeight\")\n        while len(notes) < max_notes:\n            self.scroll_page(scroll_count=2)\n            soup = BeautifulSoup(self.driver.page_source, \"html.parser\")\n            cards = soup.select(\".note-item\")\n            for card in cards:\n                try:\n                    title = card.select_one(\".title\").text.strip()\n                    author = card.select_one(\".user-name\").text.strip()\n                    likes = card.select_one(\".like-count\").text.strip()\n                    notes.append({\"title\": title, \"author\": author, \"likes\": likes})\n                except:\n                    continue\n            new_height = self.driver.execute_script(\"return document.body.scrollHeight\")\n            if new_height == last_height:\n                break\n            last_height = new_height\n        return notes[:max_notes]\n\n    def close(self):\n        self.driver.quit()\n\nif __name__ == \"__main__\":\n    crawler = XiaohongshuCrawler(headless=True)\n    try:\n        results = crawler.search(\"\u9762\u819c\u63a8\u8350\", max_notes=30)\n        print(f\"\u91c7\u96c6\u5230 {len(results)} \u7bc7\u7b14\u8bb0\")\n        for r in results:\n            print(f\"- {r['title']} | \u4f5c\u8005: {r['author']} | \u70b9\u8d5e: {r['likes']}\")\n    finally:\n        crawler.close()\n<\/code><\/pre>\n<h2>\u4e09\u3001\u5408\u89c4\u6570\u636e\u91c7\u96c6\u7684\u6700\u4f73\u5b9e\u8df5<\/h2>\n<h3>3.1 \u9075\u5b88robots.txt\u534f\u8bae<\/h3>\n<p>\u5728\u91c7\u96c6\u524d\uff0c\u9996\u5148\u68c0\u67e5\u5c0f\u7ea2\u4e66\u7684robots.txt\u6587\u4ef6\uff0c\u4e86\u89e3\u5e73\u53f0\u7684\u91c7\u96c6\u89c4\u5219\u548c\u9650\u5236\u3002<\/p>\n<pre><code>import urllib.robotparser\n\ndef check_robots_txt(base_url):\n    rp = urllib.robotparser.RobotFileParser()\n    rp.set_url(f\"{base_url}\/robots.txt\")\n    try:\n        rp.read()\n        print(f\"\u5141\u8bb8\u6293\u53d6: {rp.can_fetch('*', '\/')}\")\n        print(f\"\u5141\u8bb8Googlebot: {rp.can_fetch('Googlebot', '\/')}\")\n        for line in rp.raw(\"\/sitemap.xml\"):\n            if \"Sitemap:\" in line:\n                print(line.strip())\n    except Exception as e:\n        print(f\"\u8bfb\u53d6robots.txt\u5931\u8d25: {e}\")\n\ncheck_robots_txt(\"https:\/\/www.xiaohongshu.com\")\n<\/code><\/pre>\n<h3>3.2 \u63a7\u5236\u8bf7\u6c42\u9891\u7387<\/h3>\n<p>\u8fc7\u9ad8\u9891\u7387\u7684\u8bf7\u6c42\u4f1a\u5bf9\u76ee\u6807\u670d\u52a1\u5668\u9020\u6210\u538b\u529b\uff0c\u4e5f\u53ef\u80fd\u89e6\u53d1\u53cd\u722c\u866b\u673a\u5236\u3002\u5efa\u8bae\u5728\u6bcf\u6b21\u8bf7\u6c42\u95f4\u8bbe\u7f6e\u5408\u7406\u7684\u5ef6\u8fdf\u3002<\/p>\n<pre><code>import time\nimport threading\nfrom collections import defaultdict\n\nclass RateLimiter:\n    def __init__(self, rate=5, per=60):\n        self.rate = rate\n        self.per = per\n        self.allowance = defaultdict(int)\n        self.last_check = defaultdict(time.time)\n        self.lock = threading.Lock()\n\n    def acquire(self, key=\"default\"):\n        with self.lock:\n            current = time.time()\n            time_passed = current - self.last_check[key]\n            self.last_check[key] = current\n            self.allowance[key] += time_passed * (self.rate \/ self.per)\n            if self.allowance[key] > self.rate:\n                self.allowance[key] = self.rate\n            if self.allowance[key] < 1.0:\n                sleep_time = (1.0 - self.allowance[key]) * (self.per \/ self.rate)\n                time.sleep(sleep_time)\n                self.allowance[key] = 0\n            else:\n                self.allowance[key] -= 1.0\n            return True\n\nlimiter = RateLimiter(rate=5, per=60)\nfor i in range(10):\n    limiter.acquire()\n    print(f\"\u7b2c{i+1}\u6b21\u8bf7\u6c42\u5b8c\u6210\")\n<\/code><\/pre>\n<h3>3.3 \u6570\u636e\u5b58\u50a8\u4e0e\u5b89\u5168<\/h3>\n<pre><code>import sqlite3\nimport hashlib\nfrom datetime import datetime\n\nclass DataStorage:\n    def __init__(self, db_path=\"xiaohongshu_data.db\"):\n        self.db_path = db_path\n        self.init_db()\n\n    def init_db(self):\n        conn = sqlite3.connect(self.db_path)\n        cursor = conn.cursor()\n        cursor.execute(\"\"\"\n            CREATE TABLE IF NOT EXISTS notes (\n                id INTEGER PRIMARY KEY AUTOINCREMENT,\n                note_id TEXT UNIQUE, title TEXT, content TEXT,\n                author TEXT, author_id TEXT,\n                liked_count INTEGER, collected_count INTEGER,\n                commented_count INTEGER, topics TEXT,\n                published_at TEXT, crawled_at TEXT, keyword TEXT, md5 TEXT\n            )\n        \"\"\")\n        cursor.execute(\"\"\"\n            CREATE TABLE IF NOT EXISTS authors (\n                id INTEGER PRIMARY KEY AUTOINCREMENT,\n                author_id TEXT UNIQUE, nickname TEXT,\n                followers INTEGER, verified BOOLEAN, crawled_at TEXT\n            )\n        \"\"\")\n        cursor.execute(\"CREATE INDEX IF NOT EXISTS idx_note_id ON notes(note_id)\")\n        cursor.execute(\"CREATE INDEX IF NOT EXISTS idx_author ON notes(author_id)\")\n        cursor.execute(\"CREATE INDEX IF NOT EXISTS idx_keyword ON notes(keyword)\")\n        conn.commit()\n        conn.close()\n\n    def save_note(self, note_data):\n        conn = sqlite3.connect(self.db_path)\n        cursor = conn.cursor()\n        md5_hash = hashlib.md5(\n            (note_data.get(\"note_id\", \"\") + note_data.get(\"title\", \"\")).encode()\n        ).hexdigest()\n        try:\n            cursor.execute(\"\"\"\n                INSERT OR REPLACE INTO notes (\n                    note_id, title, content, author, author_id,\n                    liked_count, collected_count, commented_count,\n                    topics, published_at, crawled_at, keyword, md5\n                ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n            \"\"\", (\n                note_data.get(\"note_id\"), note_data.get(\"title\"),\n                note_data.get(\"content\"), note_data.get(\"author\"),\n                note_data.get(\"author_id\"), note_data.get(\"liked_count\", 0),\n                note_data.get(\"collected_count\", 0), note_data.get(\"commented_count\", 0),\n                \",\".join(note_data.get(\"topics\", [])), note_data.get(\"published_at\"),\n                datetime.now().isoformat(), note_data.get(\"keyword\"), md5_hash\n            ))\n            conn.commit()\n        finally:\n            conn.close()\n\n    def get_stats(self):\n        conn = sqlite3.connect(self.db_path)\n        cursor = conn.cursor()\n        cursor.execute(\"SELECT COUNT(*) FROM notes\")\n        total_notes = cursor.fetchone()[0]\n        cursor.execute(\"SELECT COUNT(DISTINCT author_id) FROM notes\")\n        total_authors = cursor.fetchone()[0]\n        conn.close()\n        return {\"total_notes\": total_notes, \"total_authors\": total_authors}\n\nstorage = DataStorage(\"jiayus_yuqing.db\")\nstats = storage.get_stats()\nprint(f\"\u603b\u7b14\u8bb0\u6570: {stats['total_notes']}\")\n<\/code><\/pre>\n<h2>\u56db\u3001\u8206\u60c5\u76d1\u6d4b\u7cfb\u7edf\u7684\u6784\u5efa<\/h2>\n<p>\u91c7\u96c6\u5230\u539f\u59cb\u6570\u636e\u540e\uff0c\u9700\u8981\u901a\u8fc7\u6570\u636e\u6e05\u6d17\u3001\u5206\u6790\u548c\u53ef\u89c6\u5316\uff0c\u6784\u5efa\u5b8c\u6574\u7684\u8206\u60c5\u76d1\u6d4b\u7cfb\u7edf\u3002<\/p>\n<pre><code>import pandas as pd\nfrom collections import Counter\nimport re\n\nclass SentimentAnalyzer:\n    def __init__(self):\n        self.positive_words = set([\n            \"\u4f18\u79c0\", \"\u5b8c\u7f8e\", \"\u60ca\u8273\", \"\u63a8\u8350\", \"\u503c\u5f97\", \"\u597d\u7528\", \"\u559c\u6b22\",\n            \"\u8d85\u8d5e\", \"\u975e\u5e38\", \"\u6ee1\u610f\", \"\u826f\u5fc3\", \"\u9760\u8c31\", \"\u68d2\", \"\u8d5e\"\n        ])\n        self.negative_words = set([\n            \"\u5931\u671b\", \"\u5dee\", \"\u5751\", \"\u9a97\", \"\u70c2\", \"\u96be\u7528\", \"\u540e\u6094\", \"\u5047\u8d27\",\n            \"\u8fc7\u654f\", \"\u6295\u8bc9\", \"\u7ef4\u6743\", \"\u865a\u5047\", \"\u6b3a\u9a97\", \"\u5783\u573e\", \"\u5dee\u8bc4\"\n        ])\n\n    def clean_text(self, text):\n        if not text:\n            return \"\"\n        text = re.sub(r\"[^\\u4e00-\\u9fa5a-zA-Z0-9]\", \" \", text)\n        return text.strip()\n\n    def analyze_sentiment(self, text):\n        text = self.clean_text(text)\n        positive_count = sum(1 for word in self.positive_words if word in text)\n        negative_count = sum(1 for word in self.negative_words if word in text)\n        if positive_count > negative_count:\n            return \"positive\"\n        elif negative_count > positive_count:\n            return \"negative\"\n        else:\n            return \"neutral\"\n\n    def generate_report(self, notes_data):\n        sentiments = [self.analyze_sentiment(n.get(\"content\", \"\")) for n in notes_data]\n        sentiment_dist = Counter(sentiments)\n        return {\n            \"total\": len(notes_data),\n            \"positive\": sentiment_dist.get(\"positive\", 0),\n            \"negative\": sentiment_dist.get(\"negative\", 0),\n            \"neutral\": sentiment_dist.get(\"neutral\", 0)\n        }\n\nanalyzer = SentimentAnalyzer()\nprint(analyzer.analyze_sentiment(\"\u8fd9\u6b3e\u4ea7\u54c1\u975e\u5e38\u597d\u7528\uff0c\u975e\u5e38\u63a8\u8350\uff01\"))\nprint(analyzer.analyze_sentiment(\"\u592a\u5dee\u4e86\uff0c\u5b8c\u5168\u662f\u5047\u8d27\uff0c\u9a97\u4eba\u7684\uff01\"))\n<\/code><\/pre>\n<h2>\u4e94\u3001\u7ed3\u8bed<\/h2>\n<p>\u5c0f\u7ea2\u4e66\u4f5c\u4e3a\u91cd\u8981\u7684\u793e\u4ea4\u6d41\u91cf\u5165\u53e3\uff0c\u5176\u6570\u636e\u4ef7\u503c\u4e0d\u5bb9\u5ffd\u89c6\u3002\u4f01\u4e1a\u5728\u5f00\u5c55\u8206\u60c5\u76d1\u6d4b\u5de5\u4f5c\u65f6\uff0c\u5e94\u5f53\u5728\u5408\u89c4\u7684\u524d\u63d0\u4e0b\uff0c\u5408\u7406\u5229\u7528\u6570\u636e\u6280\u672f\uff0c\u6316\u6398\u6570\u636e\u80cc\u540e\u7684\u7528\u6237\u58f0\u97f3\uff0c\u4e3a\u54c1\u724c\u51b3\u7b56\u63d0\u4f9b\u79d1\u5b66\u4f9d\u636e\u3002<\/p>\n<p>\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u672c\u6587\u4ecb\u7ecd\u7684\u6280\u672f\u65b9\u6848\u4ec5\u4f9b\u5b66\u4e60\u548c\u7814\u7a76\u4f7f\u7528\u3002\u4efb\u4f55\u5546\u4e1a\u5316\u7684\u6570\u636e\u91c7\u96c6\u884c\u4e3a\uff0c\u90fd\u5e94\u5f53\u4e8b\u5148\u53d6\u5f97\u5e73\u53f0\u6388\u6743\uff0c\u9075\u5b88\u300a\u7f51\u7edc\u5b89\u5168\u6cd5\u300b\u300a\u6570\u636e\u5b89\u5168\u6cd5\u300b\u300a\u4e2a\u4eba\u4fe1\u606f\u4fdd\u62a4\u6cd5\u300b\u7b49\u76f8\u5173\u6cd5\u5f8b\u6cd5\u89c4\uff0c\u786e\u4fdd\u6570\u636e\u91c7\u96c6\u548c\u4f7f\u7528\u7684\u5408\u6cd5\u5408\u89c4\u3002<\/p>\n<p>\u7532\u9c7c\u8206\u60c5\u76d1\u6d4b\u5e73\u53f0\u81f4\u529b\u4e8e\u4e3a\u4f01\u4e1a\u63d0\u4f9b\u4e13\u4e1a\u3001\u5408\u89c4\u7684\u8206\u60c5\u76d1\u6d4b\u89e3\u51b3\u65b9\u6848\uff0c\u652f\u6301\u5c0f\u7ea2\u4e66\u3001\u5fae\u535a\u3001\u5fae\u4fe1\u3001\u6296\u97f3\u7b49\u591a\u5e73\u53f0\u6570\u636e\u76d1\u6d4b\uff0c\u52a9\u529b\u4f01\u4e1a\u628a\u63e1\u8206\u60c5\u52a8\u6001\uff0c\u63d0\u5347\u54c1\u724c\u7ba1\u7406\u80fd\u529b\u3002<\/p>\n<p><strong>\u76f8\u5173\u9605\u8bfb\uff1a<\/strong><\/p>\n<ul>\n<li>\u300a\u8206\u60c5\u76d1\u6d4b\u4e0eAPI\u63a5\u53e3\u6570\u636e\u5bf9\u63a5\u5b9e\u6218\u6307\u5357\u300b<\/li>\n<li>\u300a\u5fae\u4fe1\u89c6\u9891\u53f7\u5185\u5bb9\u91c7\u96c6\u6280\u672f\u65b9\u6848\u8be6\u89e3\u300b<\/li>\n<li>\u300a\u7f51\u7ad9\u53cd\u722c\u866b\u673a\u5236\u4e0e\u6570\u636e\u5b89\u5168\u4fdd\u62a4\u7b56\u7565\u300b<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5f53\u4eca\u6570\u5b57\u5316\u8425\u9500\u65f6\u4ee3\uff0c\u5c0f\u7ea2\u4e66\u5df2\u6210\u4e3a\u54c1\u724c\u53e3\u7891\u4f20\u64ad\u7684\u6838\u5fc3\u9635\u5730\u3002\u6bcf\u5929\u6709\u6570\u767e\u4e07\u7528\u6237\u5728\u5e73\u53f0\u4e0a\u5206\u4eab\u6d88\u8d39\u4f53\u9a8c\u3001\u4ea7\u54c1\u6d4b\u8bc4\u548c\u751f\u6d3b\u65b9\u5f0f\u5185\u5bb9\uff0c\u8fd9\u4e9b\u6570\u636e\u5bf9\u4e8e\u4f01\u4e1a\u8206\u60c5\u76d1\u6d4b\u548c\u5e02\u573a\u7814\u7a76\u5177\u6709\u6781\u9ad8\u7684\u4ef7\u503c\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5408\u89c4\u91c7\u96c6\u5c0f\u7ea2\u4e66\u6570\u636e\uff0c\u6784\u5efa\u5b8c\u5584\u7684\u54c1\u724c\u53e3\u7891\u5206\u6790\u4f53\u7cfb\u3002 \u4e00\u3001\u5c0f\u7ea2\u4e66\u6570\u636e\u5728\u8206\u60c5\u76d1\u6d4b\u4e2d\u7684\u4ef7\u503c \u5c0f\u7ea2\u4e66\uff08Xiaohongshu\uff09\u4f5c\u4e3a\u56fd\u5185\u9886\u5148\u7684\u751f\u6d3b\u65b9\u5f0f\u5206\u4eab\u5e73\u53f0\uff0c\u5176\u7528\u6237\u7fa4\u4f53\u4ee5\u4e00\u4e8c\u7ebf\u57ce\u5e02\u7684\u5e74\u8f7b\u5973\u6027\u4e3a\u4e3b\uff0c\u6d88\u8d39\u80fd\u529b\u5f3a\uff0c\u5185\u5bb9\u6d3b\u8dc3\u5ea6\u9ad8\u3002\u5e73\u53f0\u4e0a\u7684\u7b14\u8bb0\u5185\u5bb9\u6db5\u76d6\u7f8e\u5986\u62a4\u80a4\u3001\u7a7f\u642d\u65f6\u5c1a\u3001\u6bcd\u5a74\u80b2\u513f\u3001\u65c5\u884c\u51fa\u6e38\u3001\u9910\u996e\u7f8e\u98df\u7b49\u591a\u4e2a\u9886\u57df\uff0c\u5df2\u6210\u4e3a\u6d88\u8d39\u8005\u51b3\u7b56\u7684\u91cd\u8981\u53c2\u8003\u6765\u6e90\u3002 \u5bf9\u4e8e\u4f01\u4e1a\u800c\u8a00\uff0c\u5c0f\u7ea2\u4e66\u6570\u636e\u76d1\u6d4b\u5177\u6709\u4ee5\u4e0b\u6838\u5fc3\u4ef7\u503c\uff1a 1. \u53e3\u7891\u9884\u8b66\uff1a\u901a\u8fc7\u76d1\u6d4b\u54c1\u724c\u76f8\u5173\u7b14\u8bb0\uff0c\u4f01\u4e1a\u53ef\u4ee5\u7b2c\u4e00\u65f6\u95f4\u53d1\u73b0\u8d1f\u9762\u8206\u60c5\uff0c\u53ca\u65f6\u54cd\u5e94\u5904\u7406\uff0c\u907f\u514d\u5371\u673a\u6269\u6563\u3002 2. \u7ade\u54c1\u5206\u6790\uff1a\u8ffd\u8e2a\u7ade\u54c1\u5728\u5c0f\u7ea2\u4e66\u4e0a\u7684\u58f0\u91cf\u3001\u5185\u5bb9\u7c7b\u578b\u3001\u7528\u6237\u53cd\u9988\uff0c\u4e3a\u5236\u5b9a\u8425\u9500\u7b56\u7565\u63d0\u4f9b\u6570\u636e\u652f\u6491\u3002 3. KOL\u7b5b\u9009\uff1a\u901a\u8fc7\u6570\u636e\u5206\u6790\u8bc6\u522b\u9ad8\u6027\u4ef7\u6bd4\u7684\u8170\u90e8\u535a\u4e3b\u548c\u7d20\u4eba\u7528\u6237\uff0c\u6784\u5efa\u9ad8\u6548\u7684\u79cd\u8349\u77e9\u9635\u3002 4. \u8d8b\u52bf\u6d1e\u5bdf\uff1a\u5206\u6790\u70ed\u95e8\u8bdd\u9898\u548c\u5185\u5bb9\u8d8b\u52bf\uff0c\u628a\u63e1\u5e02\u573a\u98ce\u5411\uff0c\u6307\u5bfc\u4ea7\u54c1\u7814\u53d1\u548c\u8425\u9500\u7b56\u5212\u3002 \u4e8c\u3001\u5c0f\u7ea2\u4e66\u6570\u636e\u91c7\u96c6\u7684\u6280\u672f\u539f\u7406 \u5c0f\u7ea2\u4e66\u91c7\u7528\u4e86\u591a\u79cd\u53cd\u722c\u866b\u6280\u672f\u6765\u4fdd\u62a4\u5e73\u53f0\u6570\u636e\u5b89\u5168\uff0c\u5305\u62ec\u53c2\u6570\u7b7e\u540d\u9a8c\u8bc1\u3001\u8bf7\u6c42\u9891\u7387\u9650\u5236\u3001UA\u68c0\u6d4b\u3001IP\u9650\u5236\u7b49\u3002\u5408\u89c4\u7684\u6570\u636e\u91c7\u96c6\u9700\u8981\u5728\u9075\u5b88\u5e73\u53f0\u89c4\u5219\u7684\u524d\u63d0\u4e0b\u8fdb\u884c\uff0c\u4ee5\u4e0b\u4ecb\u7ecd\u51e0\u79cd\u5e38\u89c1\u7684\u6280\u672f\u65b9\u6848\u3002 2.1 \u57fa\u4e8e\u5b98\u65b9API\u7684\u6570\u636e\u83b7\u53d6 \u5c0f\u7ea2\u4e66\u5f00\u653e\u4e86\u90e8\u5206API\u63a5\u53e3\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u7533\u8bf7\u63a5\u53e3\u6743\u9650\u83b7\u53d6\u6570\u636e\u3002\u8fd9\u79cd\u65b9\u5f0f\u6700\u4e3a\u5408\u89c4\uff0c\u6570\u636e\u8d28\u91cf\u4e5f\u6700\u9ad8\u3002 import requests import json import time import hashlib import random class XiaohongshuAPI: &#8220;&#8221;&#8221;\u5c0f\u7ea2\u4e66\u5b98\u65b9API\u8c03\u7528\u5c01\u88c5&#8221;&#8221;&#8221; def __init__(self, app_id, app_secret): self.app_id = app_id self.app_secret = app_secret self.access_token = None self.token_expires_at = 0 def get_access_token(self): if self.access_token and time.time() < self.token_expires_at: return&hellip; <br \/> <a class=\"read-more\" href=\"http:\/\/www.jiayus.com\/?p=4005\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4005","post","type-post","status-publish","format-standard","hentry","category-gsxw"],"_links":{"self":[{"href":"http:\/\/www.jiayus.com\/index.php?rest_route=\/wp\/v2\/posts\/4005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.jiayus.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jiayus.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jiayus.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jiayus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4005"}],"version-history":[{"count":1,"href":"http:\/\/www.jiayus.com\/index.php?rest_route=\/wp\/v2\/posts\/4005\/revisions"}],"predecessor-version":[{"id":4006,"href":"http:\/\/www.jiayus.com\/index.php?rest_route=\/wp\/v2\/posts\/4005\/revisions\/4006"}],"wp:attachment":[{"href":"http:\/\/www.jiayus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jiayus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4005"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jiayus.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}