{"id":1177947,"date":"2025-01-15T18:04:21","date_gmt":"2025-01-15T10:04:21","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1177947.html"},"modified":"2025-01-15T18:04:24","modified_gmt":"2025-01-15T10:04:24","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e6%8a%93%e5%8f%96%e5%be%ae%e5%8d%9a","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1177947.html","title":{"rendered":"\u5982\u4f55\u7528python\u6293\u53d6\u5fae\u535a"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25112734\/a08c20f3-83a1-4052-a71d-f7701d16a316.webp\" alt=\"\u5982\u4f55\u7528python\u6293\u53d6\u5fae\u535a\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528Python\u6293\u53d6\u5fae\u535a\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5fae\u535aAPI\u3001\u6a21\u62df\u767b\u5f55\u5e76\u722c\u53d6\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/strong>\u3002\u5176\u4e2d\uff0c<strong>\u4f7f\u7528\u5fae\u535aAPI<\/strong> \u662f\u6700\u5e38\u89c1\u4e14\u89c4\u8303\u7684\u65b9\u5f0f\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u5fae\u535aAPI\u6765\u6293\u53d6\u5fae\u535a\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u6ce8\u518c\u5fae\u535a\u5f00\u53d1\u8005\u8d26\u53f7\u5e76\u7533\u8bf7API<\/h3>\n<\/p>\n<p><h4>1\u3001\u6ce8\u518c\u5fae\u535a\u5f00\u53d1\u8005\u8d26\u53f7<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5728\u5fae\u535a\u5f00\u653e\u5e73\u53f0\uff08<a href=\"http:\/\/open.weibo.com\/%EF%BC%89%E6%B3%A8%E5%86%8C%E4%B8%80%E4%B8%AA%E5%BC%80%E5%8F%91%E8%80%85%E8%B4%A6%E5%8F%B7%E3%80%82%E6%B3%A8%E5%86%8C%E5%AE%8C%E6%88%90%E5%90%8E%EF%BC%8C%E7%99%BB%E5%BD%95%E4%BD%A0%E7%9A%84%E8%B4%A6%E5%8F%B7%E3%80%82\">http:\/\/open.weibo.com\/\uff09\u6ce8\u518c\u4e00\u4e2a\u5f00\u53d1\u8005\u8d26\u53f7\u3002\u6ce8\u518c\u5b8c\u6210\u540e\uff0c\u767b\u5f55\u4f60\u7684\u8d26\u53f7\u3002<\/a><\/p>\n<\/p>\n<p><h4>2\u3001\u521b\u5efa\u5e94\u7528<\/h4>\n<\/p>\n<p><p>\u5728\u5fae\u535a\u5f00\u653e\u5e73\u53f0\u4e2d\uff0c\u9009\u62e9\u201c\u7ba1\u7406\u4e2d\u5fc3\u201d\uff0c\u70b9\u51fb\u201c\u521b\u5efa\u5e94\u7528\u201d\u3002\u5728\u521b\u5efa\u5e94\u7528\u65f6\uff0c\u4f60\u9700\u8981\u586b\u5199\u4e00\u4e9b\u5fc5\u8981\u7684\u4fe1\u606f\uff0c\u5982\u5e94\u7528\u540d\u79f0\u3001\u5e94\u7528\u63cf\u8ff0\u3001\u5e94\u7528\u7c7b\u522b\u7b49\u3002\u521b\u5efa\u5b8c\u6210\u540e\uff0c\u4f60\u5c06\u83b7\u5f97\u5e94\u7528\u7684App Key\u548cApp Secret\uff0c\u8fd9\u4e24\u4e2a\u4fe1\u606f\u5728\u540e\u7eed\u7684API\u8c03\u7528\u4e2d\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u83b7\u53d6Access Token<\/h4>\n<\/p>\n<p><p>\u5728\u8fdb\u884cAPI\u8c03\u7528\u4e4b\u524d\uff0c\u9700\u8981\u83b7\u53d6Access Token\u3002\u4f60\u53ef\u4ee5\u5728\u201c\u7ba1\u7406\u4e2d\u5fc3\u201d\u4e0b\u7684\u201c\u6211\u7684\u5e94\u7528\u201d\u4e2d\u627e\u5230\u4f60\u521b\u5efa\u7684\u5e94\u7528\uff0c\u70b9\u51fb\u201c\u5e94\u7528\u8be6\u60c5\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u6388\u6743\u8bbe\u7f6e\u201d\u6765\u83b7\u53d6Access Token\u3002\u4f60\u9700\u8981\u8bbe\u7f6e\u4e00\u4e2a\u56de\u8c03\u5730\u5740\uff0c\u7528\u4e8e\u6388\u6743\u6210\u529f\u540e\u7684\u8df3\u8f6c\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u83b7\u53d6Access Token:<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00\u6388\u6743\u9875\u9762\uff1a<a href=\"https:\/\/api.weibo.com\/oauth2\/authorize?client_id=YOUR_APP_KEY&#038;redirect_uri=YOUR_CALLBACK_URL&#038;response_type=code\">https:\/\/api.weibo.com\/oauth2\/authorize?client_id=YOUR_APP_KEY&amp;redirect_uri=YOUR_CALLBACK_URL&amp;response_type=code<\/a><\/li>\n<li>\u7528\u6237\u767b\u5f55\u5e76\u6388\u6743\u540e\uff0c\u4f1a\u8df3\u8f6c\u5230\u56de\u8c03\u5730\u5740\uff0c\u5e76\u5e26\u6709code\u53c2\u6570\u3002<\/li>\n<li>\u4f7f\u7528code\u83b7\u53d6Access Token\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>url = &#39;https:\/\/api.weibo.com\/oauth2\/access_token&#39;<\/p>\n<p>data = {<\/p>\n<p>    &#39;client_id&#39;: &#39;YOUR_APP_KEY&#39;,<\/p>\n<p>    &#39;client_secret&#39;: &#39;YOUR_APP_SECRET&#39;,<\/p>\n<p>    &#39;grant_type&#39;: &#39;authorization_code&#39;,<\/p>\n<p>    &#39;code&#39;: &#39;CODE_FROM_CALLBACK_URL&#39;,<\/p>\n<p>    &#39;redirect_uri&#39;: &#39;YOUR_CALLBACK_URL&#39;<\/p>\n<p>}<\/p>\n<p>response = requests.post(url, data=data)<\/p>\n<p>access_token = response.json()[&#39;access_token&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528API\u6293\u53d6\u5fae\u535a\u6570\u636e<\/h3>\n<\/p>\n<p><h4>1\u3001\u83b7\u53d6\u7528\u6237\u4fe1\u606f<\/h4>\n<\/p>\n<p><p>\u83b7\u53d6\u7528\u6237\u4fe1\u606f\u662f\u6293\u53d6\u5fae\u535a\u6570\u636e\u7684\u57fa\u7840\uff0c\u9996\u5148\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u7528\u6237ID\u6216\u7528\u6237\u540d\u6765\u83b7\u53d6\u7528\u6237\u7684\u57fa\u672c\u4fe1\u606f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>def get_user_info(access_token, uid):<\/p>\n<p>    url = &#39;https:\/\/api.weibo.com\/2\/users\/show.json&#39;<\/p>\n<p>    params = {<\/p>\n<p>        &#39;access_token&#39;: access_token,<\/p>\n<p>        &#39;uid&#39;: uid<\/p>\n<p>    }<\/p>\n<p>    response = requests.get(url, params=params)<\/p>\n<p>    return response.json()<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>user_info = get_user_info(access_token, &#39;USER_ID&#39;)<\/p>\n<p>print(user_info)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u83b7\u53d6\u7528\u6237\u5fae\u535a<\/h4>\n<\/p>\n<p><p>\u83b7\u53d6\u7528\u6237\u5fae\u535a\u4e3b\u8981\u662f\u901a\u8fc7\u8c03\u7528statuses\/user_timeline\u63a5\u53e3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def get_user_timeline(access_token, uid, count=10):<\/p>\n<p>    url = &#39;https:\/\/api.weibo.com\/2\/statuses\/user_timeline.json&#39;<\/p>\n<p>    params = {<\/p>\n<p>        &#39;access_token&#39;: access_token,<\/p>\n<p>        &#39;uid&#39;: uid,<\/p>\n<p>        &#39;count&#39;: count<\/p>\n<p>    }<\/p>\n<p>    response = requests.get(url, params=params)<\/p>\n<p>    return response.json()<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>user_timeline = get_user_timeline(access_token, &#39;USER_ID&#39;)<\/p>\n<p>for status in user_timeline[&#39;statuses&#39;]:<\/p>\n<p>    print(status[&#39;text&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u83b7\u53d6\u70ed\u95e8\u5fae\u535a<\/h4>\n<\/p>\n<p><p>\u83b7\u53d6\u70ed\u95e8\u5fae\u535a\u53ef\u4ee5\u4f7f\u7528statuses\/public_timeline\u63a5\u53e3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def get_public_timeline(access_token, count=10):<\/p>\n<p>    url = &#39;https:\/\/api.weibo.com\/2\/statuses\/public_timeline.json&#39;<\/p>\n<p>    params = {<\/p>\n<p>        &#39;access_token&#39;: access_token,<\/p>\n<p>        &#39;count&#39;: count<\/p>\n<p>    }<\/p>\n<p>    response = requests.get(url, params=params)<\/p>\n<p>    return response.json()<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>public_timeline = get_public_timeline(access_token)<\/p>\n<p>for status in public_timeline[&#39;statuses&#39;]:<\/p>\n<p>    print(status[&#39;text&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u6a21\u62df\u767b\u5f55\u5e76\u722c\u53d6\u5fae\u535a<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\uff0c\u5fae\u535aAPI\u7684\u9650\u5236\u53ef\u80fd\u65e0\u6cd5\u6ee1\u8db3\u6211\u4eec\u6240\u6709\u7684\u9700\u6c42\uff0c\u8fd9\u65f6\u5019\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u6a21\u62df\u767b\u5f55\u5e76\u722c\u53d6\u5fae\u535a\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u79cd\u65b9\u5f0f\u53ef\u80fd\u4f1a\u8fdd\u53cd\u5fae\u535a\u7684\u4f7f\u7528\u534f\u8bae\uff0c\u4f7f\u7528\u65f6\u9700\u8c28\u614e\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Selenium\u6a21\u62df\u767b\u5f55<\/h4>\n<\/p>\n<p><p>Selenium\u662f\u4e00\u4e2a\u7528\u4e8e\u81ea\u52a8\u5316\u6d4f\u89c8\u5668\u64cd\u4f5c\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4e8e\u6a21\u62df\u767b\u5f55\u5fae\u535a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium import webdriver<\/p>\n<p>from selenium.webdriver.common.by import By<\/p>\n<p>from selenium.webdriver.common.keys import Keys<\/p>\n<p>import time<\/p>\n<p>def login_weibo(username, password):<\/p>\n<p>    driver = webdriver.Chrome()<\/p>\n<p>    driver.get(&#39;https:\/\/weibo.com\/login.php&#39;)<\/p>\n<p>    time.sleep(5)<\/p>\n<p>    username_field = driver.find_element(By.NAME, &#39;username&#39;)<\/p>\n<p>    password_field = driver.find_element(By.NAME, &#39;password&#39;)<\/p>\n<p>    username_field.send_keys(username)<\/p>\n<p>    password_field.send_keys(password)<\/p>\n<p>    password_field.send_keys(Keys.RETURN)<\/p>\n<p>    time.sleep(5)<\/p>\n<p>    return driver<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>driver = login_weibo(&#39;YOUR_USERNAME&#39;, &#39;YOUR_PASSWORD&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6293\u53d6\u5fae\u535a\u5185\u5bb9<\/h4>\n<\/p>\n<p><p>\u767b\u5f55\u6210\u529f\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Selenium\u6765\u6293\u53d6\u5fae\u535a\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def get_weibo_content(driver, url):<\/p>\n<p>    driver.get(url)<\/p>\n<p>    time.sleep(5)<\/p>\n<p>    weibo_contents = driver.find_elements(By.CSS_SELECTOR, &#39;.WB_text&#39;)<\/p>\n<p>    for content in weibo_contents:<\/p>\n<p>        print(content.text)<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>get_weibo_content(driver, &#39;https:\/\/weibo.com\/u\/YOUR_USER_ID&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/h3>\n<\/p>\n<p><p>\u8fd8\u6709\u4e00\u4e9b\u7b2c\u4e09\u65b9\u5e93\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u7b80\u5316\u6293\u53d6\u5fae\u535a\u7684\u8fc7\u7a0b\uff0c\u6bd4\u5982<code>weibo<\/code>\u5e93\u3002\u8fd9\u4e2a\u5e93\u5c01\u88c5\u4e86\u5fae\u535aAPI\uff0c\u53ef\u4ee5\u66f4\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u6293\u53d6\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5weibo\u5e93<\/h4>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install weibo<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528weibo\u5e93\u6293\u53d6\u5fae\u535a\u6570\u636e<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from weibo import Client<\/p>\n<p>client = Client(api_key=&#39;YOUR_APP_KEY&#39;, api_secret=&#39;YOUR_APP_SECRET&#39;, redirect_uri=&#39;YOUR_CALLBACK_URL&#39;)<\/p>\n<p>client.set_code(&#39;CODE_FROM_CALLBACK_URL&#39;)<\/p>\n<h2><strong>\u83b7\u53d6\u7528\u6237\u4fe1\u606f<\/strong><\/h2>\n<p>user_info = client.get(&#39;users\/show&#39;, uid=&#39;USER_ID&#39;)<\/p>\n<p>print(user_info)<\/p>\n<h2><strong>\u83b7\u53d6\u7528\u6237\u5fae\u535a<\/strong><\/h2>\n<p>user_timeline = client.get(&#39;statuses\/user_timeline&#39;, uid=&#39;USER_ID&#39;, count=10)<\/p>\n<p>for status in user_timeline[&#39;statuses&#39;]:<\/p>\n<p>    print(status[&#39;text&#39;])<\/p>\n<h2><strong>\u83b7\u53d6\u70ed\u95e8\u5fae\u535a<\/strong><\/h2>\n<p>public_timeline = client.get(&#39;statuses\/public_timeline&#39;, count=10)<\/p>\n<p>for status in public_timeline[&#39;statuses&#39;]:<\/p>\n<p>    print(status[&#39;text&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u6570\u636e\u5b58\u50a8\u4e0e\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u6293\u53d6\u5230\u7684\u6570\u636e\u53ef\u4ee5\u5b58\u50a8\u5230\u672c\u5730\u6587\u4ef6\u6216\u6570\u636e\u5e93\u4e2d\uff0c\u4ee5\u4fbf\u540e\u7eed\u5904\u7406\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b58\u50a8\u5230\u672c\u5730\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import json<\/p>\n<p>def save_to_file(data, filename):<\/p>\n<p>    with open(filename, &#39;w&#39;, encoding=&#39;utf-8&#39;) as f:<\/p>\n<p>        json.dump(data, f, ensure_ascii=False, indent=4)<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>save_to_file(user_timeline, &#39;user_timeline.json&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5b58\u50a8\u5230\u6570\u636e\u5e93<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528SQLite\u6216\u5176\u4ed6\u6570\u636e\u5e93\u6765\u5b58\u50a8\u6293\u53d6\u5230\u7684\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sqlite3<\/p>\n<p>def save_to_db(data, db_name=&#39;weibo.db&#39;):<\/p>\n<p>    conn = sqlite3.connect(db_name)<\/p>\n<p>    c = conn.cursor()<\/p>\n<p>    c.execute(&#39;&#39;&#39;CREATE TABLE IF NOT EXISTS weibo<\/p>\n<p>                 (id INTEGER PRIMARY KEY, text TEXT)&#39;&#39;&#39;)<\/p>\n<p>    for status in data[&#39;statuses&#39;]:<\/p>\n<p>        c.execute(&quot;INSERT INTO weibo (id, text) VALUES (?, ?)&quot;, (status[&#39;id&#39;], status[&#39;text&#39;]))<\/p>\n<p>    conn.commit()<\/p>\n<p>    conn.close()<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>save_to_db(user_timeline)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u6570\u636e\u5206\u6790\u4e0e\u53ef\u89c6\u5316<\/h3>\n<\/p>\n<p><p>\u6293\u53d6\u5230\u7684\u6570\u636e\u53ef\u4ee5\u8fdb\u884c\u5404\u79cd\u5206\u6790\u548c\u53ef\u89c6\u5316\u64cd\u4f5c\uff0c\u4ee5\u83b7\u53d6\u6709\u4ef7\u503c\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u8bcd\u9891\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>jieba<\/code>\u5e93\u8fdb\u884c\u4e2d\u6587\u5206\u8bcd\uff0c\u5e76\u4f7f\u7528<code>collections<\/code>\u5e93\u8fdb\u884c\u8bcd\u9891\u7edf\u8ba1\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import jieba<\/p>\n<p>from collections import Counter<\/p>\n<p>def analyze_word_frequency(texts):<\/p>\n<p>    words = []<\/p>\n<p>    for text in texts:<\/p>\n<p>        words.extend(jieba.cut(text))<\/p>\n<p>    word_count = Counter(words)<\/p>\n<p>    return word_count<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>texts = [status[&#39;text&#39;] for status in user_timeline[&#39;statuses&#39;]]<\/p>\n<p>word_count = analyze_word_frequency(texts)<\/p>\n<p>print(word_count.most_common(10))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u60c5\u611f\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>snownlp<\/code>\u5e93\u8fdb\u884c\u60c5\u611f\u5206\u6790\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from snownlp import SnowNLP<\/p>\n<p>def analyze_sentiment(texts):<\/p>\n<p>    sentiments = []<\/p>\n<p>    for text in texts:<\/p>\n<p>        s = SnowNLP(text)<\/p>\n<p>        sentiments.append(s.sentiments)<\/p>\n<p>    return sentiments<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>sentiments = analyze_sentiment(texts)<\/p>\n<p>print(sentiments)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u53ef\u89c6\u5316<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>matplotlib<\/code>\u6216<code>pandas<\/code>\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>def plot_word_frequency(word_count):<\/p>\n<p>    words, counts = zip(*word_count.most_common(10))<\/p>\n<p>    plt.bar(words, counts)<\/p>\n<p>    plt.show()<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>plot_word_frequency(word_count)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u6293\u53d6\u5fae\u535a\u6570\u636e\uff0c\u5e76\u8fdb\u884c\u6570\u636e\u5b58\u50a8\u3001\u5206\u6790\u548c\u53ef\u89c6\u5316\u3002\u65e0\u8bba\u662f\u4f7f\u7528\u5fae\u535aAPI\u3001\u6a21\u62df\u767b\u5f55\u8fd8\u662f\u7b2c\u4e09\u65b9\u5e93\uff0c<strong>\u6570\u636e\u7684\u5408\u6cd5\u6027\u548c\u9690\u79c1\u4fdd\u62a4<\/strong>\u90fd\u9700\u8981\u6211\u4eec\u7279\u522b\u6ce8\u610f\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6293\u53d6\u5230\u7684\u6570\u636e\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u8fdb\u884c\u5404\u79cd\u6709\u4ef7\u503c\u7684\u5206\u6790\u548c\u7814\u7a76\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u5e93\u6765\u6293\u53d6\u5fae\u535a\u6570\u636e\uff1f<\/strong><br \/>\u5728\u4f7f\u7528Python\u6293\u53d6\u5fae\u535a\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u9009\u62e9\u591a\u4e2a\u5e93\uff0c\u5982Requests\u3001BeautifulSoup\u548cScrapy\u7b49\u3002Requests\u5e93\u53ef\u4ee5\u5e2e\u52a9\u4f60\u53d1\u9001HTTP\u8bf7\u6c42\uff0c\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\uff0c\u800cBeautifulSoup\u5219\u53ef\u4ee5\u89e3\u6790HTML\u6587\u6863\uff0c\u63d0\u53d6\u6240\u9700\u7684\u4fe1\u606f\u3002Scrapy\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u6846\u67b6\uff0c\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u6293\u53d6\u3002\u6839\u636e\u4f60\u7684\u9700\u6c42\u548c\u6293\u53d6\u590d\u6742\u5ea6\uff0c\u9009\u62e9\u6700\u9002\u5408\u7684\u5e93\u3002<\/p>\n<p><strong>\u6293\u53d6\u5fae\u535a\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u6cd5\u5f8b\u6cd5\u89c4\uff1f<\/strong><br \/>\u5728\u6293\u53d6\u5fae\u535a\u6570\u636e\u65f6\uff0c\u9075\u5faa\u76f8\u5173\u6cd5\u5f8b\u6cd5\u89c4\u975e\u5e38\u91cd\u8981\u3002\u786e\u4fdd\u9075\u5faa\u6570\u636e\u4fdd\u62a4\u6cd5\u548c\u9690\u79c1\u653f\u7b56\uff0c\u907f\u514d\u6293\u53d6\u7528\u6237\u7684\u79c1\u4eba\u4fe1\u606f\u3002\u6b64\u5916\uff0c\u4e86\u89e3\u5fae\u535a\u7684\u4f7f\u7528\u6761\u6b3e\uff0c\u786e\u4fdd\u4e0d\u8fdd\u53cd\u5e73\u53f0\u7684\u9650\u5236\uff0c\u5982\u9891\u7e41\u8bf7\u6c42\u53ef\u80fd\u5bfc\u81f4\u8d26\u53f7\u88ab\u5c01\u7981\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u6293\u53d6\u8fc7\u7a0b\u4e2d\u9047\u5230\u7684\u53cd\u722c\u866b\u673a\u5236\uff1f<\/strong><br \/>\u5fae\u535a\u7b49\u793e\u4ea4\u5e73\u53f0\u901a\u5e38\u4f1a\u5b9e\u65bd\u53cd\u722c\u866b\u673a\u5236\u3002\u4e3a\u4e86\u5e94\u5bf9\u8fd9\u4e9b\u6311\u6218\uff0c\u53ef\u4ee5\u91c7\u53d6\u591a\u79cd\u7b56\u7565\uff0c\u5982\u8bbe\u7f6e\u8bf7\u6c42\u5934\u4ee5\u6a21\u62df\u6d4f\u89c8\u5668\u884c\u4e3a\u3001\u4f7f\u7528\u4ee3\u7406IP\u6765\u9690\u85cf\u771f\u5b9e\u5730\u5740\u3001\u4ee5\u53ca\u63a7\u5236\u8bf7\u6c42\u9891\u7387\u4ee5\u907f\u514d\u88ab\u8bc6\u522b\u4e3a\u722c\u866b\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u968f\u673a\u5ef6\u8fdf\u4e5f\u6709\u52a9\u4e8e\u964d\u4f4e\u88ab\u5c01\u7981\u7684\u98ce\u9669\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u6293\u53d6\u5fae\u535a\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5fae\u535aAPI\u3001\u6a21\u62df\u767b\u5f55\u5e76\u722c\u53d6\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u3002\u5176\u4e2d\uff0c\u4f7f\u7528\u5fae\u535aAPI \u662f\u6700\u5e38\u89c1 [&hellip;]","protected":false},"author":3,"featured_media":1177952,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1177947"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1177947"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1177947\/revisions"}],"predecessor-version":[{"id":1177955,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1177947\/revisions\/1177955"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1177952"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1177947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1177947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1177947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}