{"id":1119731,"date":"2025-01-08T18:47:26","date_gmt":"2025-01-08T10:47:26","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1119731.html"},"modified":"2025-01-08T18:47:29","modified_gmt":"2025-01-08T10:47:29","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e7%88%ac%e4%b8%89%e5%9b%bd%e6%bc%94%e4%b9%89","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1119731.html","title":{"rendered":"\u5982\u4f55\u7528python\u722c\u4e09\u56fd\u6f14\u4e49"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25082710\/48382799-88ca-4014-9100-9860468c5a6a.webp\" alt=\"\u5982\u4f55\u7528python\u722c\u4e09\u56fd\u6f14\u4e49\" \/><\/p>\n<p><p> <strong>\u5728\u7528Python\u722c\u53d6\u300a\u4e09\u56fd\u6f14\u4e49\u300b\u5185\u5bb9\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u7684\u6280\u672f\u548c\u65b9\u6cd5\u5305\u62ec\uff1arequests\u5e93\u3001BeautifulSoup\u5e93\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u3001\u5b58\u50a8\u6570\u636e\u3002\u9996\u5148\uff0c\u4f7f\u7528requests\u5e93\u53d1\u9001HTTP\u8bf7\u6c42\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\uff0c\u7136\u540e\u4f7f\u7528BeautifulSoup\u5e93\u89e3\u6790HTML\uff0c\u6700\u540e\u5c06\u63d0\u53d6\u5230\u7684\u6570\u636e\u5b58\u50a8\u5230\u5408\u9002\u7684\u6587\u4ef6\u6216\u6570\u636e\u5e93\u4e2d\u3002\u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u7684\u4e00\u79cd\u65b9\u6cd5\u2014\u2014\u4f7f\u7528requests\u5e93\u548cBeautifulSoup\u5e93\u6765\u722c\u53d6\u300a\u4e09\u56fd\u6f14\u4e49\u300b\u7684\u7ae0\u8282\u5185\u5bb9\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u83b7\u53d6\u7f51\u9875\u5185\u5bb9<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u722c\u53d6\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u627e\u5230\u300a\u4e09\u56fd\u6f14\u4e49\u300b\u7684\u5728\u7ebf\u6587\u672c\u8d44\u6e90\u3002\u5047\u8bbe\u6211\u4eec\u627e\u5230\u4e86\u4e00\u4e2a\u5305\u542b\u300a\u4e09\u56fd\u6f14\u4e49\u300b\u6587\u672c\u7684\u7f51\u7ad9\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528requests\u5e93\u6765\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>url = &#39;https:\/\/example.com\/sanguo&#39;  # \u66ff\u6362\u4e3a\u5b9e\u9645\u7684URL<\/p>\n<p>response = requests.get(url)<\/p>\n<p>if response.status_code == 200:<\/p>\n<p>    page_content = response.text<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;F<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>led to retrieve content. Status code: {response.status_code}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u89e3\u6790\u7f51\u9875\u5185\u5bb9<\/h3>\n<\/p>\n<p><p>\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\u540e\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528BeautifulSoup\u5e93\u6765\u89e3\u6790HTML\u5e76\u63d0\u53d6\u6211\u4eec\u9700\u8981\u7684\u6570\u636e\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5BeautifulSoup\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install beautifulsoup4<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u89e3\u6790\u7f51\u9875\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from bs4 import BeautifulSoup<\/p>\n<p>soup = BeautifulSoup(page_content, &#39;html.parser&#39;)<\/p>\n<h2><strong>\u5047\u8bbe\u7ae0\u8282\u5185\u5bb9\u5728\u4e00\u4e2a\u7279\u5b9a\u7684HTML\u6807\u7b7e\u4e2d\uff0c\u4f8b\u5982&lt;div class=&quot;chapter&quot;&gt;<\/strong><\/h2>\n<p>chapters = soup.find_all(&#39;div&#39;, class_=&#39;chapter&#39;)<\/p>\n<p>for chapter in chapters:<\/p>\n<p>    title = chapter.find(&#39;h2&#39;).text  # \u5047\u8bbe\u7ae0\u8282\u6807\u9898\u5728&lt;h2&gt;\u6807\u7b7e\u4e2d<\/p>\n<p>    content = chapter.find(&#39;p&#39;).text  # \u5047\u8bbe\u7ae0\u8282\u5185\u5bb9\u5728&lt;p&gt;\u6807\u7b7e\u4e2d<\/p>\n<p>    print(f&quot;Title: {title}&quot;)<\/p>\n<p>    print(f&quot;Content: {content}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u63d0\u53d6\u5185\u5bb9<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u7f51\u9875\u7ed3\u6784\u53ef\u80fd\u4e0d\u90a3\u4e48\u7b80\u5355\uff0c\u76f4\u63a5\u4f7f\u7528BeautifulSoup\u5e93\u53ef\u80fd\u65e0\u6cd5\u63d0\u53d6\u5230\u6211\u4eec\u9700\u8981\u7684\u6570\u636e\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u63d0\u53d6\u5185\u5bb9\u3002\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u6587\u672c\u5339\u914d\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u4ece\u590d\u6742\u7684HTML\u4e2d\u63d0\u53d6\u6240\u9700\u7684\u6570\u636e\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<h2><strong>\u5047\u8bbe\u7ae0\u8282\u5185\u5bb9\u5728\u4e00\u4e2a\u7279\u5b9a\u7684HTML\u6807\u7b7e\u4e2d\uff0c\u4f8b\u5982&lt;div class=&quot;chapter&quot;&gt;<\/strong><\/h2>\n<p>pattern = re.compile(r&#39;&lt;div class=&quot;chapter&quot;&gt;(.*?)&lt;\/div&gt;&#39;, re.DOTALL)<\/p>\n<p>matches = pattern.findall(page_content)<\/p>\n<p>for match in matches:<\/p>\n<p>    title_pattern = re.compile(r&#39;&lt;h2&gt;(.*?)&lt;\/h2&gt;&#39;)<\/p>\n<p>    content_pattern = re.compile(r&#39;&lt;p&gt;(.*?)&lt;\/p&gt;&#39;)<\/p>\n<p>    title = title_pattern.search(match).group(1)<\/p>\n<p>    content = content_pattern.search(match).group(1)<\/p>\n<p>    print(f&quot;Title: {title}&quot;)<\/p>\n<p>    print(f&quot;Content: {content}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5b58\u50a8\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u63d0\u53d6\u5230\u300a\u4e09\u56fd\u6f14\u4e49\u300b\u7684\u7ae0\u8282\u5185\u5bb9\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u5b58\u50a8\u5230\u4e00\u4e2a\u6587\u4ef6\u6216\u6570\u636e\u5e93\u4e2d\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u5c06\u6570\u636e\u5b58\u50a8\u5230\u6587\u672c\u6587\u4ef6\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">with open(&#39;sanguo.txt&#39;, &#39;w&#39;, encoding=&#39;utf-8&#39;) as file:<\/p>\n<p>    for chapter in chapters:<\/p>\n<p>        title = chapter.find(&#39;h2&#39;).text<\/p>\n<p>        content = chapter.find(&#39;p&#39;).text<\/p>\n<p>        file.write(f&quot;Title: {title}\\n&quot;)<\/p>\n<p>        file.write(f&quot;Content: {content}\\n\\n&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u6211\u4eec\u9700\u8981\u5c06\u6570\u636e\u5b58\u50a8\u5230\u6570\u636e\u5e93\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528SQLite\u3001MySQL\u6216\u5176\u4ed6\u6570\u636e\u5e93\u7cfb\u7edf\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u5c06\u6570\u636e\u5b58\u50a8\u5230SQLite\u6570\u636e\u5e93\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sqlite3<\/p>\n<h2><strong>\u521b\u5efaSQLite\u6570\u636e\u5e93\u8fde\u63a5<\/strong><\/h2>\n<p>conn = sqlite3.connect(&#39;sanguo.db&#39;)<\/p>\n<p>c = conn.cursor()<\/p>\n<h2><strong>\u521b\u5efa\u8868<\/strong><\/h2>\n<p>c.execute(&#39;&#39;&#39;CREATE TABLE IF NOT EXISTS chapters<\/p>\n<p>             (id INTEGER PRIMARY KEY, title TEXT, content TEXT)&#39;&#39;&#39;)<\/p>\n<h2><strong>\u63d2\u5165\u6570\u636e<\/strong><\/h2>\n<p>for chapter in chapters:<\/p>\n<p>    title = chapter.find(&#39;h2&#39;).text<\/p>\n<p>    content = chapter.find(&#39;p&#39;).text<\/p>\n<p>    c.execute(&quot;INSERT INTO chapters (title, content) VALUES (?, ?)&quot;, (title, content))<\/p>\n<h2><strong>\u63d0\u4ea4\u4e8b\u52a1\u5e76\u5173\u95ed\u8fde\u63a5<\/strong><\/h2>\n<p>conn.commit()<\/p>\n<p>conn.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u5904\u7406\u5206\u9875<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u300a\u4e09\u56fd\u6f14\u4e49\u300b\u7684\u5185\u5bb9\u5206\u5e03\u5728\u591a\u4e2a\u9875\u9762\u4e0a\uff0c\u6211\u4eec\u9700\u8981\u5904\u7406\u5206\u9875\u60c5\u51b5\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5faa\u73af\u904d\u5386\u6bcf\u4e00\u9875\u6765\u83b7\u53d6\u6240\u6709\u7ae0\u8282\u5185\u5bb9\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>from bs4 import BeautifulSoup<\/p>\n<p>base_url = &#39;https:\/\/example.com\/sanguo?page=&#39;  # \u66ff\u6362\u4e3a\u5b9e\u9645\u7684\u5206\u9875URL<\/p>\n<p>page_number = 1<\/p>\n<p>while True:<\/p>\n<p>    url = base_url + str(page_number)<\/p>\n<p>    response = requests.get(url)<\/p>\n<p>    if response.status_code != 200:<\/p>\n<p>        break<\/p>\n<p>    page_content = response.text<\/p>\n<p>    soup = BeautifulSoup(page_content, &#39;html.parser&#39;)<\/p>\n<p>    chapters = soup.find_all(&#39;div&#39;, class_=&#39;chapter&#39;)<\/p>\n<p>    if not chapters:<\/p>\n<p>        break<\/p>\n<p>    for chapter in chapters:<\/p>\n<p>        title = chapter.find(&#39;h2&#39;).text<\/p>\n<p>        content = chapter.find(&#39;p&#39;).text<\/p>\n<p>        print(f&quot;Title: {title}&quot;)<\/p>\n<p>        print(f&quot;Content: {content}&quot;)<\/p>\n<p>    page_number += 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u5904\u7406\u53cd\u722c\u866b\u673a\u5236<\/h3>\n<\/p>\n<p><p>\u4e00\u4e9b\u7f51\u7ad9\u53ef\u80fd\u4f1a\u6709\u53cd\u722c\u866b\u673a\u5236\u6765\u9632\u6b62\u81ea\u52a8\u5316\u722c\u53d6\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u6280\u5de7\u6765\u7ed5\u8fc7\u53cd\u722c\u866b\u673a\u5236\uff0c\u4f8b\u5982\u8bbe\u7f6e\u8bf7\u6c42\u5934\u3001\u4f7f\u7528\u4ee3\u7406\u3001\u6dfb\u52a0\u5ef6\u8fdf\u7b49\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>from bs4 import BeautifulSoup<\/p>\n<p>import time<\/p>\n<p>headers = {<\/p>\n<p>    &#39;User-Agent&#39;: &#39;Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/58.0.3029.110 Safari\/537.3&#39;}<\/p>\n<p>base_url = &#39;https:\/\/example.com\/sanguo?page=&#39;  # \u66ff\u6362\u4e3a\u5b9e\u9645\u7684\u5206\u9875URL<\/p>\n<p>page_number = 1<\/p>\n<p>while True:<\/p>\n<p>    url = base_url + str(page_number)<\/p>\n<p>    response = requests.get(url, headers=headers)<\/p>\n<p>    if response.status_code != 200:<\/p>\n<p>        break<\/p>\n<p>    page_content = response.text<\/p>\n<p>    soup = BeautifulSoup(page_content, &#39;html.parser&#39;)<\/p>\n<p>    chapters = soup.find_all(&#39;div&#39;, class_=&#39;chapter&#39;)<\/p>\n<p>    if not chapters:<\/p>\n<p>        break<\/p>\n<p>    for chapter in chapters:<\/p>\n<p>        title = chapter.find(&#39;h2&#39;).text<\/p>\n<p>        content = chapter.find(&#39;p&#39;).text<\/p>\n<p>        print(f&quot;Title: {title}&quot;)<\/p>\n<p>        print(f&quot;Content: {content}&quot;)<\/p>\n<p>    page_number += 1<\/p>\n<p>    time.sleep(2)  # \u6dfb\u52a0\u5ef6\u8fdf\uff0c\u907f\u514d\u89e6\u53d1\u53cd\u722c\u866b\u673a\u5236<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u5904\u7406\u52a8\u6001\u5185\u5bb9<\/h3>\n<\/p>\n<p><p>\u6709\u4e9b\u7f51\u7ad9\u7684\u5185\u5bb9\u662f\u901a\u8fc7JavaScript\u52a8\u6001\u52a0\u8f7d\u7684\uff0c\u76f4\u63a5\u8bf7\u6c42HTML\u9875\u9762\u53ef\u80fd\u65e0\u6cd5\u83b7\u53d6\u5230\u5b8c\u6574\u5185\u5bb9\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Selenium\u5e93\u6765\u6a21\u62df\u6d4f\u89c8\u5668\u64cd\u4f5c\uff0c\u83b7\u53d6\u52a8\u6001\u52a0\u8f7d\u7684\u5185\u5bb9\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5Selenium\u5e93\u548c\u6d4f\u89c8\u5668\u9a71\u52a8\u7a0b\u5e8f\uff08\u4f8b\u5982ChromeDriver\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install selenium<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u83b7\u53d6\u52a8\u6001\u52a0\u8f7d\u7684\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium import webdriver<\/p>\n<p>from bs4 import BeautifulSoup<\/p>\n<p>driver = webdriver.Chrome()  # \u66ff\u6362\u4e3a\u5b9e\u9645\u7684\u6d4f\u89c8\u5668\u9a71\u52a8\u7a0b\u5e8f<\/p>\n<p>base_url = &#39;https:\/\/example.com\/sanguo?page=&#39;  # \u66ff\u6362\u4e3a\u5b9e\u9645\u7684\u5206\u9875URL<\/p>\n<p>page_number = 1<\/p>\n<p>while True:<\/p>\n<p>    url = base_url + str(page_number)<\/p>\n<p>    driver.get(url)<\/p>\n<p>    page_content = driver.page_source<\/p>\n<p>    soup = BeautifulSoup(page_content, &#39;html.parser&#39;)<\/p>\n<p>    chapters = soup.find_all(&#39;div&#39;, class_=&#39;chapter&#39;)<\/p>\n<p>    if not chapters:<\/p>\n<p>        break<\/p>\n<p>    for chapter in chapters:<\/p>\n<p>        title = chapter.find(&#39;h2&#39;).text<\/p>\n<p>        content = chapter.find(&#39;p&#39;).text<\/p>\n<p>        print(f&quot;Title: {title}&quot;)<\/p>\n<p>        print(f&quot;Content: {content}&quot;)<\/p>\n<p>    page_number += 1<\/p>\n<p>driver.quit()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u5904\u7406\u9a8c\u8bc1\u7801<\/h3>\n<\/p>\n<p><p>\u6709\u4e9b\u7f51\u7ad9\u53ef\u80fd\u4f1a\u4f7f\u7528\u9a8c\u8bc1\u7801\u6765\u9632\u6b62\u81ea\u52a8\u5316\u722c\u53d6\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u7b2c\u4e09\u65b9\u670d\u52a1\u6765\u89e3\u51b3\u9a8c\u8bc1\u7801\u95ee\u9898\uff0c\u4f8b\u5982\u6253\u7801\u5e73\u53f0\u6216OCR\uff08\u5149\u5b66\u5b57\u7b26\u8bc6\u522b\uff09\u5de5\u5177\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u4f7f\u7528\u6253\u7801\u5e73\u53f0\u6765\u89e3\u51b3\u9a8c\u8bc1\u7801\u95ee\u9898\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>from bs4 import BeautifulSoup<\/p>\n<h2><strong>\u66ff\u6362\u4e3a\u5b9e\u9645\u7684\u6253\u7801\u5e73\u53f0API<\/strong><\/h2>\n<p>captcha_api_url = &#39;https:\/\/example.com\/captcha_api&#39;<\/p>\n<p>captcha_api_key = &#39;your_api_key&#39;<\/p>\n<p>def solve_captcha(captcha_image_url):<\/p>\n<p>    response = requests.get(captcha_image_url)<\/p>\n<p>    captcha_image = response.content<\/p>\n<p>    # \u8c03\u7528\u6253\u7801\u5e73\u53f0API\u89e3\u51b3\u9a8c\u8bc1\u7801<\/p>\n<p>    response = requests.post(captcha_api_url, files={&#39;file&#39;: captcha_image}, data={&#39;key&#39;: captcha_api_key})<\/p>\n<p>    captcha_solution = response.json()[&#39;solution&#39;]<\/p>\n<p>    return captcha_solution<\/p>\n<h2><strong>\u5047\u8bbe\u9a8c\u8bc1\u7801\u56fe\u7247URL\u5728\u9875\u9762\u7684\u4e00\u4e2a\u7279\u5b9aHTML\u6807\u7b7e\u4e2d<\/strong><\/h2>\n<p>soup = BeautifulSoup(page_content, &#39;html.parser&#39;)<\/p>\n<p>captcha_image_url = soup.find(&#39;img&#39;, class_=&#39;captcha&#39;)[&#39;src&#39;]<\/p>\n<p>captcha_solution = solve_captcha(captcha_image_url)<\/p>\n<p>print(f&quot;Captcha Solution: {captcha_solution}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528requests\u5e93\u3001BeautifulSoup\u5e93\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u3001Selenium\u5e93\u4ee5\u53ca\u5904\u7406\u5206\u9875\u3001\u53cd\u722c\u866b\u673a\u5236\u3001\u52a8\u6001\u5185\u5bb9\u548c\u9a8c\u8bc1\u7801\u7b49\u6280\u672f\uff0c\u6211\u4eec\u53ef\u4ee5\u6210\u529f\u5730\u722c\u53d6\u300a\u4e09\u56fd\u6f14\u4e49\u300b\u7684\u5185\u5bb9\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u722c\u866b\u8fc7\u7a0b\u4e2d\u5e94\u9075\u5b88\u7f51\u7ad9\u7684robots.txt\u534f\u8bae\u548c\u76f8\u5173\u6cd5\u5f8b\u6cd5\u89c4\uff0c\u907f\u514d\u7ed9\u7f51\u7ad9\u5e26\u6765\u4e0d\u5fc5\u8981\u7684\u8d1f\u62c5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u6293\u53d6\u300a\u4e09\u56fd\u6f14\u4e49\u300b\u7684\u6570\u636e\uff1f<\/strong><br \/>\u8981\u6293\u53d6\u300a\u4e09\u56fd\u6f14\u4e49\u300b\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684\u722c\u866b\u6846\u67b6\u5982Scrapy\u6216BeautifulSoup\u3002\u9996\u5148\uff0c\u9700\u8981\u4e86\u89e3\u76ee\u6807\u7f51\u7ad9\u7684\u7ed3\u6784\uff0c\u786e\u5b9a\u8981\u6293\u53d6\u7684\u5185\u5bb9\uff0c\u6bd4\u5982\u7ae0\u8282\u3001\u4eba\u7269\u4ecb\u7ecd\u7b49\u3002\u901a\u8fc7\u53d1\u9001HTTP\u8bf7\u6c42\u83b7\u53d6\u9875\u9762\u5185\u5bb9\u540e\uff0c\u89e3\u6790HTML\uff0c\u63d0\u53d6\u6240\u9700\u4fe1\u606f\u5e76\u5b58\u50a8\u5230\u6587\u4ef6\u6216\u6570\u636e\u5e93\u4e2d\u3002\u786e\u4fdd\u9075\u5b88robots.txt\u534f\u8bae\uff0c\u907f\u514d\u5bf9\u7f51\u7ad9\u9020\u6210\u8d1f\u62c5\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u722c\u866b\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u6cd5\u5f8b\u548c\u4f26\u7406\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u8fdb\u884c\u722c\u866b\u65f6\uff0c\u6cd5\u5f8b\u548c\u4f26\u7406\u95ee\u9898\u975e\u5e38\u91cd\u8981\u3002\u786e\u4fdd\u9075\u5faa\u7f51\u7ad9\u7684\u4f7f\u7528\u6761\u6b3e\uff0c\u4e0d\u8981\u6293\u53d6\u654f\u611f\u6216\u53d7\u7248\u6743\u4fdd\u62a4\u7684\u5185\u5bb9\u3002\u540c\u65f6\uff0c\u5408\u7406\u8bbe\u7f6e\u8bf7\u6c42\u9891\u7387\uff0c\u907f\u514d\u5bf9\u76ee\u6807\u7f51\u7ad9\u9020\u6210\u8fc7\u591a\u8d1f\u8f7d\u3002\u5c0a\u91cd\u6570\u636e\u6240\u6709\u8005\u7684\u6743\u5229\uff0c\u5fc5\u8981\u65f6\u53ef\u4ee5\u5148\u8054\u7cfb\u7f51\u7ad9\u7ba1\u7406\u5458\u83b7\u53d6\u6293\u53d6\u8bb8\u53ef\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u6293\u53d6\u5230\u7684\u6570\u636e\u4ee5\u4fbf\u540e\u7eed\u5206\u6790\uff1f<\/strong><br \/>\u6293\u53d6\u5230\u7684\u300a\u4e09\u56fd\u6f14\u4e49\u300b\u6570\u636e\u53ef\u4ee5\u8fdb\u884c\u591a\u79cd\u5904\u7406\u3002\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u5c06\u6570\u636e\u8f6c\u6362\u4e3aDataFrame\u683c\u5f0f\uff0c\u4fbf\u4e8e\u5206\u6790\u548c\u53ef\u89c6\u5316\u3002\u901a\u8fc7\u6570\u636e\u6e05\u6d17\uff0c\u53bb\u9664\u91cd\u590d\u548c\u65e0\u6548\u7684\u4fe1\u606f\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u6570\u636e\u5206\u6790\u5de5\u5177\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\uff0c\u6216\u8005\u5229\u7528Matplotlib\u548cSeaborn\u7b49\u5e93\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\uff0c\u5e2e\u52a9\u66f4\u597d\u5730\u7406\u89e3\u6545\u4e8b\u60c5\u8282\u548c\u4eba\u7269\u5173\u7cfb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728\u7528Python\u722c\u53d6\u300a\u4e09\u56fd\u6f14\u4e49\u300b\u5185\u5bb9\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u7684\u6280\u672f\u548c\u65b9\u6cd5\u5305\u62ec\uff1arequests\u5e93\u3001BeautifulSou [&hellip;]","protected":false},"author":3,"featured_media":1119742,"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\/1119731"}],"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=1119731"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1119731\/revisions"}],"predecessor-version":[{"id":1119745,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1119731\/revisions\/1119745"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1119742"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1119731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1119731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1119731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}