{"id":1174037,"date":"2025-01-15T17:11:28","date_gmt":"2025-01-15T09:11:28","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1174037.html"},"modified":"2025-01-15T17:11:30","modified_gmt":"2025-01-15T09:11:30","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e7%88%ac%e5%8f%96%e5%95%86%e5%93%81","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1174037.html","title":{"rendered":"\u5982\u4f55\u7528python\u722c\u53d6\u5546\u54c1"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26075629\/60b6888a-5925-42ec-876c-8600e6171640.webp\" alt=\"\u5982\u4f55\u7528python\u722c\u53d6\u5546\u54c1\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528Python\u722c\u53d6\u5546\u54c1\u7684\u5173\u952e\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u5408\u9002\u7684\u5e93\u3001\u83b7\u53d6\u76ee\u6807\u7f51\u9875\u7684URL\u3001\u89e3\u6790\u7f51\u9875\u6570\u636e\u3001\u5b58\u50a8\u6570\u636e<\/strong>\u3002\u5176\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684\u5e93\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u6b65\uff0c\u56e0\u4e3a\u4e0d\u540c\u7684\u5e93\u6709\u4e0d\u540c\u7684\u529f\u80fd\u548c\u9002\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u9009\u62e9\u5408\u9002\u7684\u5e93<\/h3>\n<\/p>\n<ol>\n<li><strong>Requests\u5e93<\/strong>\uff1a\u7528\u4e8e\u53d1\u9001HTTP\u8bf7\u6c42\uff0c\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\u3002Requests\u5e93\u662f\u4e00\u4e2a\u7b80\u5355\u6613\u7528\u4e14\u529f\u80fd\u5f3a\u5927\u7684HTTP\u5e93\uff0c\u9002\u7528\u4e8e\u5927\u90e8\u5206\u7684\u7f51\u9875\u6293\u53d6\u4efb\u52a1\u3002<\/li>\n<li><strong>BeautifulSoup\u5e93<\/strong>\uff1a\u7528\u4e8e\u89e3\u6790HTML\u548cXML\u6587\u6863\uff0c\u63d0\u53d6\u6570\u636e\u3002BeautifulSoup\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bf9\u7f51\u9875\u5185\u5bb9\u8fdb\u884c\u89e3\u6790\u548c\u5904\u7406\uff0c\u662f\u6570\u636e\u63d0\u53d6\u7684\u5229\u5668\u3002<\/li>\n<li><strong>Selenium\u5e93<\/strong>\uff1a\u7528\u4e8e\u6a21\u62df\u6d4f\u89c8\u5668\u64cd\u4f5c\uff0c\u9002\u5408\u52a8\u6001\u7f51\u9875\u7684\u6293\u53d6\u3002\u5bf9\u4e8e\u9700\u8981\u6267\u884cJavaScript\u624d\u80fd\u83b7\u53d6\u7684\u5185\u5bb9\uff0cSelenium\u5e93\u80fd\u591f\u6a21\u62df\u7528\u6237\u64cd\u4f5c\uff0c\u52a0\u8f7d\u52a8\u6001\u5185\u5bb9\u3002<\/li>\n<li><strong>Scrapy\u6846\u67b6<\/strong>\uff1a\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u722c\u866b\u6846\u67b6\uff0c\u9002\u7528\u4e8e\u5927\u89c4\u6a21\u6570\u636e\u722c\u53d6\u548c\u5904\u7406\u3002Scrapy\u6846\u67b6\u96c6\u6210\u4e86\u6570\u636e\u6293\u53d6\u3001\u6570\u636e\u6e05\u6d17\u3001\u6570\u636e\u5b58\u50a8\u7b49\u529f\u80fd\uff0c\u9002\u5408\u590d\u6742\u7684\u722c\u866b\u9879\u76ee\u3002<\/li>\n<\/ol>\n<p><p>\u9009\u62e9\u5408\u9002\u7684\u5e93\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u5b9e\u9645\u7684\u722c\u53d6\u64cd\u4f5c\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u5e93\u6765\u5b8c\u6210\u5546\u54c1\u6570\u636e\u7684\u722c\u53d6\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u83b7\u53d6\u76ee\u6807\u7f51\u9875\u7684URL<\/h3>\n<\/p>\n<p><p>\u83b7\u53d6\u76ee\u6807\u7f51\u9875\u7684URL\u662f\u722c\u53d6\u5546\u54c1\u6570\u636e\u7684\u7b2c\u4e00\u6b65\u3002\u901a\u5e38\uff0c\u6211\u4eec\u9700\u8981\u786e\u5b9a\u8981\u722c\u53d6\u7684\u7535\u5546\u5e73\u53f0\u548c\u5177\u4f53\u7684\u5546\u54c1\u9875\u9762\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u722c\u53d6\u4e9a\u9a6c\u900a\u3001\u4eac\u4e1c\u3001\u6dd8\u5b9d\u7b49\u7535\u5546\u5e73\u53f0\u7684\u5546\u54c1\u6570\u636e\u3002\u4ee5\u4e9a\u9a6c\u900a\u4e3a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u4e00\u4e2a\u5177\u4f53\u7684\u5546\u54c1\u9875\u9762URL\u8fdb\u884c\u722c\u53d6\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u89e3\u6790\u7f51\u9875\u6570\u636e<\/h3>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528Requests\u548cBeautifulSoup<\/strong><\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5Requests\u548cBeautifulSoup\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install requests<\/p>\n<p>pip install beautifulsoup4<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u7f16\u5199\u4ee3\u7801\u6765\u83b7\u53d6\u5e76\u89e3\u6790\u7f51\u9875\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>from bs4 import BeautifulSoup<\/p>\n<h2><strong>\u83b7\u53d6\u7f51\u9875\u5185\u5bb9<\/strong><\/h2>\n<p>url = &#39;https:\/\/www.amazon.com\/dp\/B08N5WRWNW&#39;<\/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\/91.0.4472.124 Safari\/537.36&#39;<\/p>\n<p>}<\/p>\n<p>response = requests.get(url, headers=headers)<\/p>\n<h2><strong>\u89e3\u6790\u7f51\u9875\u5185\u5bb9<\/strong><\/h2>\n<p>soup = BeautifulSoup(response.content, &#39;html.parser&#39;)<\/p>\n<p>product_title = soup.find(&#39;span&#39;, {&#39;id&#39;: &#39;productTitle&#39;}).text.strip()<\/p>\n<p>product_price = soup.find(&#39;span&#39;, {&#39;id&#39;: &#39;priceblock_ourprice&#39;}).text.strip()<\/p>\n<p>print(f&#39;\u5546\u54c1\u540d\u79f0: {product_title}&#39;)<\/p>\n<p>print(f&#39;\u5546\u54c1\u4ef7\u683c: {product_price}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528Requests\u5e93\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\uff0c\u5e76\u6dfb\u52a0\u4e86User-Agent\u5934\u4fe1\u606f\uff0c\u4ee5\u6a21\u62df\u6d4f\u89c8\u5668\u8bf7\u6c42\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528BeautifulSoup\u5e93\u89e3\u6790\u7f51\u9875\u5185\u5bb9\uff0c\u63d0\u53d6\u5546\u54c1\u540d\u79f0\u548c\u4ef7\u683c\u4fe1\u606f\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528Selenium<\/strong><\/li>\n<\/ol>\n<p><p>\u5bf9\u4e8e\u52a8\u6001\u7f51\u9875\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Selenium\u5e93\u8fdb\u884c\u722c\u53d6\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5Selenium\u5e93\u548c\u6d4f\u89c8\u5668\u9a71\u52a8\uff08\u5982ChromeDriver\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install selenium<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u7f16\u5199\u4ee3\u7801\u6765\u4f7f\u7528Selenium\u6a21\u62df\u6d4f\u89c8\u5668\u64cd\u4f5c\uff0c\u83b7\u53d6\u52a8\u6001\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium import webdriver<\/p>\n<p>from selenium.webdriver.chrome.service import Service<\/p>\n<p>from selenium.webdriver.common.by import By<\/p>\n<p>from selenium.webdriver.chrome.options import Options<\/p>\n<h2><strong>\u8bbe\u7f6eChrome\u9009\u9879<\/strong><\/h2>\n<p>chrome_options = Options()<\/p>\n<p>chrome_options.add_argument(&#39;--headless&#39;)<\/p>\n<p>chrome_options.add_argument(&#39;--disable-gpu&#39;)<\/p>\n<h2><strong>\u521d\u59cb\u5316\u6d4f\u89c8\u5668\u9a71\u52a8<\/strong><\/h2>\n<p>service = Service(&#39;\/path\/to\/chromedriver&#39;)<\/p>\n<p>driver = webdriver.Chrome(service=service, options=chrome_options)<\/p>\n<h2><strong>\u6253\u5f00\u7f51\u9875<\/strong><\/h2>\n<p>url = &#39;https:\/\/www.amazon.com\/dp\/B08N5WRWNW&#39;<\/p>\n<p>driver.get(url)<\/p>\n<h2><strong>\u7b49\u5f85\u9875\u9762\u52a0\u8f7d\u5b8c\u6210<\/strong><\/h2>\n<p>driver.implicitly_w<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>t(10)<\/p>\n<h2><strong>\u83b7\u53d6\u5546\u54c1\u4fe1\u606f<\/strong><\/h2>\n<p>product_title = driver.find_element(By.ID, &#39;productTitle&#39;).text<\/p>\n<p>product_price = driver.find_element(By.ID, &#39;priceblock_ourprice&#39;).text<\/p>\n<p>print(f&#39;\u5546\u54c1\u540d\u79f0: {product_title}&#39;)<\/p>\n<p>print(f&#39;\u5546\u54c1\u4ef7\u683c: {product_price}&#39;)<\/p>\n<h2><strong>\u5173\u95ed\u6d4f\u89c8\u5668<\/strong><\/h2>\n<p>driver.quit()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Selenium\u5e93\u521d\u59cb\u5316\u6d4f\u89c8\u5668\u9a71\u52a8\uff0c\u5e76\u8bbe\u7f6e\u6d4f\u89c8\u5668\u9009\u9879\u4e3a\u65e0\u5934\u6a21\u5f0f\uff08headless\uff09\u3002\u63a5\u7740\uff0c\u6211\u4eec\u6253\u5f00\u5546\u54c1\u9875\u9762\uff0c\u5e76\u7b49\u5f85\u9875\u9762\u52a0\u8f7d\u5b8c\u6210\u540e\uff0c\u63d0\u53d6\u5546\u54c1\u540d\u79f0\u548c\u4ef7\u683c\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5b58\u50a8\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u722c\u53d6\u5230\u5546\u54c1\u6570\u636e\u540e\uff0c\u6211\u4eec\u9700\u8981\u5c06\u5176\u5b58\u50a8\u5230\u672c\u5730\u6216\u6570\u636e\u5e93\u4e2d\uff0c\u4ee5\u4fbf\u540e\u7eed\u5206\u6790\u548c\u5904\u7406\u3002\u5e38\u7528\u7684\u6570\u636e\u5b58\u50a8\u65b9\u5f0f\u5305\u62ecCSV\u6587\u4ef6\u3001JSON\u6587\u4ef6\u548c\u6570\u636e\u5e93\uff08\u5982MySQL\u3001MongoDB\u7b49\uff09\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b58\u50a8\u5230CSV\u6587\u4ef6<\/strong><\/li>\n<\/ol>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u5185\u7f6e\u7684csv\u6a21\u5757\u5c06\u6570\u636e\u5b58\u50a8\u5230CSV\u6587\u4ef6\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import csv<\/p>\n<h2><strong>\u5b9a\u4e49\u5546\u54c1\u6570\u636e<\/strong><\/h2>\n<p>product_data = [<\/p>\n<p>    {&#39;name&#39;: &#39;\u5546\u54c11&#39;, &#39;price&#39;: &#39;100\u5143&#39;},<\/p>\n<p>    {&#39;name&#39;: &#39;\u5546\u54c12&#39;, &#39;price&#39;: &#39;200\u5143&#39;}<\/p>\n<p>]<\/p>\n<h2><strong>\u5199\u5165CSV\u6587\u4ef6<\/strong><\/h2>\n<p>with open(&#39;products.csv&#39;, &#39;w&#39;, newline=&#39;&#39;, encoding=&#39;utf-8&#39;) as file:<\/p>\n<p>    writer = csv.DictWriter(file, fieldnames=[&#39;name&#39;, &#39;price&#39;])<\/p>\n<p>    writer.writeheader()<\/p>\n<p>    writer.writerows(product_data)<\/p>\n<p>print(&#39;\u5546\u54c1\u6570\u636e\u5df2\u4fdd\u5b58\u5230products.csv\u6587\u4ef6\u4e2d&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5546\u54c1\u6570\u636e\u5217\u8868\uff0c\u5e76\u4f7f\u7528csv.DictWriter\u5c06\u5176\u5199\u5165CSV\u6587\u4ef6\u4e2d\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5b58\u50a8\u5230JSON\u6587\u4ef6<\/strong><\/li>\n<\/ol>\n<p><p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528Python\u5185\u7f6e\u7684json\u6a21\u5757\u5c06\u6570\u636e\u5b58\u50a8\u5230JSON\u6587\u4ef6\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import json<\/p>\n<h2><strong>\u5b9a\u4e49\u5546\u54c1\u6570\u636e<\/strong><\/h2>\n<p>product_data = [<\/p>\n<p>    {&#39;name&#39;: &#39;\u5546\u54c11&#39;, &#39;price&#39;: &#39;100\u5143&#39;},<\/p>\n<p>    {&#39;name&#39;: &#39;\u5546\u54c12&#39;, &#39;price&#39;: &#39;200\u5143&#39;}<\/p>\n<p>]<\/p>\n<h2><strong>\u5199\u5165JSON\u6587\u4ef6<\/strong><\/h2>\n<p>with open(&#39;products.json&#39;, &#39;w&#39;, encoding=&#39;utf-8&#39;) as file:<\/p>\n<p>    json.dump(product_data, file, ensure_ascii=False, indent=4)<\/p>\n<p>print(&#39;\u5546\u54c1\u6570\u636e\u5df2\u4fdd\u5b58\u5230products.json\u6587\u4ef6\u4e2d&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5546\u54c1\u6570\u636e\u5217\u8868\uff0c\u5e76\u4f7f\u7528json.dump\u5c06\u5176\u5199\u5165JSON\u6587\u4ef6\u4e2d\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5b58\u50a8\u5230\u6570\u636e\u5e93<\/strong><\/li>\n<\/ol>\n<p><p>\u5bf9\u4e8e\u5927\u89c4\u6a21\u6570\u636e\u5b58\u50a8\uff0c\u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u5c06\u6570\u636e\u5b58\u50a8\u5230\u6570\u636e\u5e93\u4e2d\u3002\u4ee5\u4e0b\u662f\u5c06\u6570\u636e\u5b58\u50a8\u5230MySQL\u6570\u636e\u5e93\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import mysql.connector<\/p>\n<h2><strong>\u8fde\u63a5\u5230MySQL\u6570\u636e\u5e93<\/strong><\/h2>\n<p>db = mysql.connector.connect(<\/p>\n<p>    host=&#39;localhost&#39;,<\/p>\n<p>    user=&#39;your_username&#39;,<\/p>\n<p>    password=&#39;your_password&#39;,<\/p>\n<p>    database=&#39;your_database&#39;<\/p>\n<p>)<\/p>\n<h2><strong>\u521b\u5efa\u6e38\u6807\u5bf9\u8c61<\/strong><\/h2>\n<p>cursor = db.cursor()<\/p>\n<h2><strong>\u521b\u5efa\u5546\u54c1\u8868<\/strong><\/h2>\n<p>cursor.execute(&#39;&#39;&#39;<\/p>\n<p>    CREATE TABLE IF NOT EXISTS products (<\/p>\n<p>        id INT AUTO_INCREMENT PRIMARY KEY,<\/p>\n<p>        name VARCHAR(255),<\/p>\n<p>        price VARCHAR(255)<\/p>\n<p>    )<\/p>\n<p>&#39;&#39;&#39;)<\/p>\n<h2><strong>\u5b9a\u4e49\u5546\u54c1\u6570\u636e<\/strong><\/h2>\n<p>product_data = [<\/p>\n<p>    {&#39;name&#39;: &#39;\u5546\u54c11&#39;, &#39;price&#39;: &#39;100\u5143&#39;},<\/p>\n<p>    {&#39;name&#39;: &#39;\u5546\u54c12&#39;, &#39;price&#39;: &#39;200\u5143&#39;}<\/p>\n<p>]<\/p>\n<h2><strong>\u63d2\u5165\u6570\u636e\u5230\u5546\u54c1\u8868<\/strong><\/h2>\n<p>for product in product_data:<\/p>\n<p>    cursor.execute(&#39;&#39;&#39;<\/p>\n<p>        INSERT INTO products (name, price)<\/p>\n<p>        VALUES (%s, %s)<\/p>\n<p>    &#39;&#39;&#39;, (product[&#39;name&#39;], product[&#39;price&#39;]))<\/p>\n<h2><strong>\u63d0\u4ea4\u4e8b\u52a1<\/strong><\/h2>\n<p>db.commit()<\/p>\n<p>print(&#39;\u5546\u54c1\u6570\u636e\u5df2\u4fdd\u5b58\u5230MySQL\u6570\u636e\u5e93\u4e2d&#39;)<\/p>\n<h2><strong>\u5173\u95ed\u8fde\u63a5<\/strong><\/h2>\n<p>cursor.close()<\/p>\n<p>db.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528mysql.connector\u8fde\u63a5\u5230MySQL\u6570\u636e\u5e93\uff0c\u5e76\u521b\u5efa\u5546\u54c1\u8868\u3002\u63a5\u7740\uff0c\u6211\u4eec\u5c06\u5546\u54c1\u6570\u636e\u63d2\u5165\u5230\u5546\u54c1\u8868\u4e2d\uff0c\u5e76\u63d0\u4ea4\u4e8b\u52a1\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5904\u7406\u53cd\u722c\u866b\u673a\u5236<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u7684\u5546\u54c1\u6570\u636e\u722c\u53d6\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u9047\u5230\u53cd\u722c\u866b\u673a\u5236\u7684\u963b\u788d\u3002\u5e38\u89c1\u7684\u53cd\u722c\u866b\u673a\u5236\u5305\u62ecIP\u5c01\u7981\u3001\u9a8c\u8bc1\u7801\u3001\u52a8\u6001\u5185\u5bb9\u52a0\u8f7d\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u53cd\u722c\u866b\u5904\u7406\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u4ee3\u7406IP<\/strong><\/li>\n<\/ol>\n<p><p>\u4f7f\u7528\u4ee3\u7406IP\u53ef\u4ee5\u6709\u6548\u5730\u89c4\u907fIP\u5c01\u7981\u95ee\u9898\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee3\u7406IP\u6c60\u8f6e\u6362\u4f7f\u7528\u4e0d\u540c\u7684IP\u5730\u5740\uff0c\u907f\u514d\u88ab\u76ee\u6807\u7f51\u7ad9\u5c01\u7981\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<h2><strong>\u5b9a\u4e49\u4ee3\u7406IP\u5217\u8868<\/strong><\/h2>\n<p>proxies = [<\/p>\n<p>    &#39;http:\/\/123.123.123.123:8080&#39;,<\/p>\n<p>    &#39;http:\/\/124.124.124.124:8080&#39;<\/p>\n<p>]<\/p>\n<h2><strong>\u8f6e\u6362\u4f7f\u7528\u4ee3\u7406IP<\/strong><\/h2>\n<p>for proxy in proxies:<\/p>\n<p>    response = requests.get(&#39;https:\/\/www.amazon.com\/dp\/B08N5WRWNW&#39;, proxies={&#39;http&#39;: proxy, &#39;https&#39;: proxy})<\/p>\n<p>    print(response.status_code)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528\u5934\u4fe1\u606f<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u8bf7\u6c42\u5934\u4e2d\u6dfb\u52a0User-Agent\u3001Referer\u3001Cookies\u7b49\u4fe1\u606f\uff0c\u53ef\u4ee5\u6a21\u62df\u6d4f\u89c8\u5668\u8bf7\u6c42\uff0c\u589e\u52a0\u8bf7\u6c42\u7684\u771f\u5b9e\u6027\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<h2><strong>\u5b9a\u4e49\u8bf7\u6c42\u5934<\/strong><\/h2>\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\/91.0.4472.124 Safari\/537.36&#39;,<\/p>\n<p>    &#39;Referer&#39;: &#39;https:\/\/www.amazon.com\/&#39;,<\/p>\n<p>    &#39;Cookies&#39;: &#39;your_cookies_here&#39;<\/p>\n<p>}<\/p>\n<h2><strong>\u53d1\u9001\u8bf7\u6c42<\/strong><\/h2>\n<p>response = requests.get(&#39;https:\/\/www.amazon.com\/dp\/B08N5WRWNW&#39;, headers=headers)<\/p>\n<p>print(response.status_code)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6a21\u62df\u7528\u6237\u64cd\u4f5c<\/strong><\/li>\n<\/ol>\n<p><p>\u5bf9\u4e8e\u9700\u8981\u6267\u884cJavaScript\u624d\u80fd\u83b7\u53d6\u7684\u5185\u5bb9\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Selenium\u6a21\u62df\u7528\u6237\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u6eda\u52a8\u9875\u9762\u3001\u70b9\u51fb\u6309\u94ae\u7b49\u64cd\u4f5c\uff0c\u53ef\u4ee5\u52a0\u8f7d\u66f4\u591a\u7684\u52a8\u6001\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium import webdriver<\/p>\n<p>from selenium.webdriver.common.keys import Keys<\/p>\n<h2><strong>\u521d\u59cb\u5316\u6d4f\u89c8\u5668\u9a71\u52a8<\/strong><\/h2>\n<p>driver = webdriver.Chrome()<\/p>\n<h2><strong>\u6253\u5f00\u7f51\u9875<\/strong><\/h2>\n<p>url = &#39;https:\/\/www.amazon.com\/dp\/B08N5WRWNW&#39;<\/p>\n<p>driver.get(url)<\/p>\n<h2><strong>\u6a21\u62df\u6eda\u52a8\u9875\u9762<\/strong><\/h2>\n<p>driver.find_element_by_tag_name(&#39;body&#39;).send_keys(Keys.END)<\/p>\n<h2><strong>\u7b49\u5f85\u9875\u9762\u52a0\u8f7d\u5b8c\u6210<\/strong><\/h2>\n<p>driver.implicitly_wait(10)<\/p>\n<h2><strong>\u83b7\u53d6\u5546\u54c1\u4fe1\u606f<\/strong><\/h2>\n<p>product_title = driver.find_element_by_id(&#39;productTitle&#39;).text<\/p>\n<p>product_price = driver.find_element_by_id(&#39;priceblock_ourprice&#39;).text<\/p>\n<p>print(f&#39;\u5546\u54c1\u540d\u79f0: {product_title}&#39;)<\/p>\n<p>print(f&#39;\u5546\u54c1\u4ef7\u683c: {product_price}&#39;)<\/p>\n<h2><strong>\u5173\u95ed\u6d4f\u89c8\u5668<\/strong><\/h2>\n<p>driver.quit()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Selenium\u6a21\u62df\u6d4f\u89c8\u5668\u64cd\u4f5c\uff0c\u6253\u5f00\u5546\u54c1\u9875\u9762\u5e76\u6eda\u52a8\u5230\u9875\u9762\u5e95\u90e8\uff0c\u4ee5\u52a0\u8f7d\u66f4\u591a\u7684\u52a8\u6001\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u6570\u636e\u6e05\u6d17\u548c\u5206\u6790<\/h3>\n<\/p>\n<p><p>\u5728\u83b7\u53d6\u5230\u5546\u54c1\u6570\u636e\u540e\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u548c\u5206\u6790\uff0c\u4ee5\u4fbf\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u4fe1\u606f\u3002\u5e38\u89c1\u7684\u6570\u636e\u6e05\u6d17\u548c\u5206\u6790\u64cd\u4f5c\u5305\u62ec\u6570\u636e\u53bb\u91cd\u3001\u7f3a\u5931\u503c\u5904\u7406\u3001\u6570\u636e\u683c\u5f0f\u8f6c\u6362\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u6570\u636e\u53bb\u91cd<\/strong><\/li>\n<\/ol>\n<p><p>\u6570\u636e\u53bb\u91cd\u53ef\u4ee5\u53bb\u9664\u91cd\u590d\u7684\u5546\u54c1\u6570\u636e\uff0c\u4fdd\u8bc1\u6570\u636e\u7684\u552f\u4e00\u6027\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6\u5546\u54c1\u6570\u636e<\/strong><\/h2>\n<p>df = pd.read_csv(&#39;products.csv&#39;)<\/p>\n<h2><strong>\u53bb\u9664\u91cd\u590d\u6570\u636e<\/strong><\/h2>\n<p>df.drop_duplicates(inplace=True)<\/p>\n<h2><strong>\u4fdd\u5b58\u53bb\u91cd\u540e\u7684\u6570\u636e<\/strong><\/h2>\n<p>df.to_csv(&#39;products_clean.csv&#39;, index=False)<\/p>\n<p>print(&#39;\u5546\u54c1\u6570\u636e\u5df2\u53bb\u91cd\u5e76\u4fdd\u5b58\u5230products_clean.csv\u6587\u4ef6\u4e2d&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Pandas\u5e93\u8bfb\u53d6\u5546\u54c1\u6570\u636e\uff0c\u5e76\u4f7f\u7528drop_duplicates\u65b9\u6cd5\u53bb\u9664\u91cd\u590d\u6570\u636e\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u7f3a\u5931\u503c\u5904\u7406<\/strong><\/li>\n<\/ol>\n<p><p>\u7f3a\u5931\u503c\u5904\u7406\u53ef\u4ee5\u586b\u8865\u6216\u5220\u9664\u6570\u636e\u4e2d\u7684\u7f3a\u5931\u503c\uff0c\u4fdd\u8bc1\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6\u5546\u54c1\u6570\u636e<\/strong><\/h2>\n<p>df = pd.read_csv(&#39;products.csv&#39;)<\/p>\n<h2><strong>\u586b\u8865\u7f3a\u5931\u503c<\/strong><\/h2>\n<p>df.fillna(&#39;\u672a\u77e5&#39;, inplace=True)<\/p>\n<h2><strong>\u4fdd\u5b58\u5904\u7406\u540e\u7684\u6570\u636e<\/strong><\/h2>\n<p>df.to_csv(&#39;products_clean.csv&#39;, index=False)<\/p>\n<p>print(&#39;\u5546\u54c1\u6570\u636e\u4e2d\u7684\u7f3a\u5931\u503c\u5df2\u5904\u7406\u5e76\u4fdd\u5b58\u5230products_clean.csv\u6587\u4ef6\u4e2d&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Pandas\u5e93\u8bfb\u53d6\u5546\u54c1\u6570\u636e\uff0c\u5e76\u4f7f\u7528fillna\u65b9\u6cd5\u586b\u8865\u7f3a\u5931\u503c\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6570\u636e\u683c\u5f0f\u8f6c\u6362<\/strong><\/li>\n<\/ol>\n<p><p>\u6570\u636e\u683c\u5f0f\u8f6c\u6362\u53ef\u4ee5\u5c06\u6570\u636e\u8f6c\u6362\u4e3a\u7edf\u4e00\u7684\u683c\u5f0f\uff0c\u4fbf\u4e8e\u540e\u7eed\u5206\u6790\u3002\u4f8b\u5982\uff0c\u5c06\u4ef7\u683c\u6570\u636e\u8f6c\u6362\u4e3a\u6570\u503c\u578b\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6\u5546\u54c1\u6570\u636e<\/strong><\/h2>\n<p>df = pd.read_csv(&#39;products.csv&#39;)<\/p>\n<h2><strong>\u5c06\u4ef7\u683c\u6570\u636e\u8f6c\u6362\u4e3a\u6570\u503c\u578b<\/strong><\/h2>\n<p>df[&#39;price&#39;] = df[&#39;price&#39;].str.replace(&#39;\u5143&#39;, &#39;&#39;).astype(float)<\/p>\n<h2><strong>\u4fdd\u5b58\u5904\u7406\u540e\u7684\u6570\u636e<\/strong><\/h2>\n<p>df.to_csv(&#39;products_clean.csv&#39;, index=False)<\/p>\n<p>print(&#39;\u5546\u54c1\u6570\u636e\u7684\u4ef7\u683c\u5df2\u8f6c\u6362\u4e3a\u6570\u503c\u578b\u5e76\u4fdd\u5b58\u5230products_clean.csv\u6587\u4ef6\u4e2d&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Pandas\u5e93\u8bfb\u53d6\u5546\u54c1\u6570\u636e\uff0c\u5e76\u4f7f\u7528str.replace\u548castype\u65b9\u6cd5\u5c06\u4ef7\u683c\u6570\u636e\u8f6c\u6362\u4e3a\u6570\u503c\u578b\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u6570\u636e\u53ef\u89c6\u5316<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u53ef\u89c6\u5316\u53ef\u4ee5\u76f4\u89c2\u5730\u5c55\u793a\u5546\u54c1\u6570\u636e\u7684\u5206\u5e03\u548c\u53d8\u5316\u8d8b\u52bf\uff0c\u4fbf\u4e8e\u5206\u6790\u548c\u51b3\u7b56\u3002\u5e38\u7528\u7684\u6570\u636e\u53ef\u89c6\u5316\u5de5\u5177\u5305\u62ecMatplotlib\u3001Seaborn\u3001Plotly\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528Matplotlib\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316<\/strong><\/li>\n<\/ol>\n<p><p>Matplotlib\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u6570\u636e\u53ef\u89c6\u5316\u5e93\uff0c\u9002\u7528\u4e8e\u7ed8\u5236\u5404\u79cd\u56fe\u8868\u3002\u4f8b\u5982\uff0c\u7ed8\u5236\u5546\u54c1\u4ef7\u683c\u5206\u5e03\u56fe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u8bfb\u53d6\u5546\u54c1\u6570\u636e<\/strong><\/h2>\n<p>df = pd.read_csv(&#39;products_clean.csv&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\u5546\u54c1\u4ef7\u683c\u5206\u5e03\u56fe<\/strong><\/h2>\n<p>plt.hist(df[&#39;price&#39;], bins=20, edgecolor=&#39;k&#39;)<\/p>\n<p>plt.xlabel(&#39;\u4ef7\u683c&#39;)<\/p>\n<p>plt.ylabel(&#39;\u6570\u91cf&#39;)<\/p>\n<p>plt.title(&#39;\u5546\u54c1\u4ef7\u683c\u5206\u5e03\u56fe&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Pandas\u5e93\u8bfb\u53d6\u5546\u54c1\u6570\u636e\uff0c\u5e76\u4f7f\u7528Matplotlib\u5e93\u7ed8\u5236\u5546\u54c1\u4ef7\u683c\u5206\u5e03\u56fe\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528Seaborn\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316<\/strong><\/li>\n<\/ol>\n<p><p>Seaborn\u662f\u4e00\u4e2a\u57fa\u4e8eMatplotlib\u7684\u6570\u636e\u53ef\u89c6\u5316\u5e93\uff0c\u9002\u7528\u4e8e\u7ed8\u5236\u590d\u6742\u7684\u7edf\u8ba1\u56fe\u8868\u3002\u4f8b\u5982\uff0c\u7ed8\u5236\u5546\u54c1\u4ef7\u683c\u4e0e\u8bc4\u5206\u7684\u5173\u7cfb\u56fe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import seaborn as sns<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u8bfb\u53d6\u5546\u54c1\u6570\u636e<\/strong><\/h2>\n<p>df = pd.read_csv(&#39;products_clean.csv&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\u5546\u54c1\u4ef7\u683c\u4e0e\u8bc4\u5206\u7684\u5173\u7cfb\u56fe<\/strong><\/h2>\n<p>sns.scatterplot(x=&#39;price&#39;, y=&#39;rating&#39;, data=df)<\/p>\n<p>plt.xlabel(&#39;\u4ef7\u683c&#39;)<\/p>\n<p>plt.ylabel(&#39;\u8bc4\u5206&#39;)<\/p>\n<p>plt.title(&#39;\u5546\u54c1\u4ef7\u683c\u4e0e\u8bc4\u5206\u7684\u5173\u7cfb\u56fe&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Pandas\u5e93\u8bfb\u53d6\u5546\u54c1\u6570\u636e\uff0c\u5e76\u4f7f\u7528Seaborn\u5e93\u7ed8\u5236\u5546\u54c1\u4ef7\u683c\u4e0e\u8bc4\u5206\u7684\u5173\u7cfb\u56fe\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u4f7f\u7528Plotly\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316<\/strong><\/li>\n<\/ol>\n<p><p>Plotly\u662f\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u6570\u636e\u53ef\u89c6\u5316\u5e93\uff0c\u9002\u7528\u4e8e\u7ed8\u5236\u4ea4\u4e92\u5f0f\u56fe\u8868\u3002\u4f8b\u5982\uff0c\u7ed8\u5236\u5546\u54c1\u4ef7\u683c\u53d8\u5316\u8d8b\u52bf\u56fe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import plotly.express as px<\/p>\n<h2><strong>\u8bfb\u53d6\u5546\u54c1\u6570\u636e<\/strong><\/h2>\n<p>df = pd.read_csv(&#39;products_clean.csv&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\u5546\u54c1\u4ef7\u683c\u53d8\u5316\u8d8b\u52bf\u56fe<\/strong><\/h2>\n<p>fig = px.line(df, x=&#39;date&#39;, y=&#39;price&#39;, title=&#39;\u5546\u54c1\u4ef7\u683c\u53d8\u5316\u8d8b\u52bf\u56fe&#39;)<\/p>\n<p>fig.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Pandas\u5e93\u8bfb\u53d6\u5546\u54c1\u6570\u636e\uff0c\u5e76\u4f7f\u7528Plotly\u5e93\u7ed8\u5236\u5546\u54c1\u4ef7\u683c\u53d8\u5316\u8d8b\u52bf\u56fe\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Python\u722c\u53d6\u5546\u54c1\u6570\u636e\u7684\u5173\u952e\u6b65\u9aa4\uff0c\u5305\u62ec\u9009\u62e9\u5408\u9002\u7684\u5e93\u3001\u83b7\u53d6\u76ee\u6807\u7f51\u9875\u7684URL\u3001\u89e3\u6790\u7f51\u9875\u6570\u636e\u3001\u5b58\u50a8\u6570\u636e\u3001\u5904\u7406\u53cd\u722c\u866b\u673a\u5236\u3001\u6570\u636e\u6e05\u6d17\u548c\u5206\u6790\u3001\u6570\u636e\u53ef\u89c6\u5316\u7b49\u3002\u901a\u8fc7\u5b9e\u9645\u4ee3\u7801\u793a\u4f8b\uff0c\u6211\u4eec\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528Requests\u548cBeautifulSoup\u5e93\u3001Selenium\u5e93\u3001Scrapy\u6846\u67b6\u7b49\u5de5\u5177\u8fdb\u884c\u5546\u54c1\u6570\u636e\u722c\u53d6\uff0c\u5e76\u4ecb\u7ecd\u4e86\u6570\u636e\u5b58\u50a8\u3001\u6e05\u6d17\u3001\u5206\u6790\u548c\u53ef\u89c6\u5316\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u7684\u5546\u54c1\u6570\u636e\u722c\u53d6\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e\u76ee\u6807\u7f51\u7ad9\u7684\u5177\u4f53\u60c5\u51b5\uff0c\u9009\u62e9\u5408\u9002\u7684\u722c\u53d6\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u5e76\u6ce8\u610f\u5904\u7406\u53cd\u722c\u866b\u673a\u5236\u3002\u540c\u65f6\uff0c\u6570\u636e\u6e05\u6d17\u548c\u5206\u6790\u662f\u6570\u636e\u5904\u7406\u7684\u91cd\u8981\u73af\u8282\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u4fe1\u606f\uff0c\u4e3a\u540e\u7eed\u7684\u5206\u6790\u548c\u51b3\u7b56\u63d0\u4f9b\u652f\u6301\u3002\u5e0c\u671b\u672c\u6587\u80fd\u591f\u5e2e\u52a9\u5927\u5bb6\u66f4\u597d\u5730\u638c\u63e1Python\u722c\u53d6\u5546\u54c1\u6570\u636e\u7684\u65b9\u6cd5\u548c\u6280\u5de7\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684Python\u5e93\u8fdb\u884c\u5546\u54c1\u722c\u53d6\uff1f<\/strong><br \/>\u5728\u8fdb\u884c\u5546\u54c1\u722c\u53d6\u65f6\uff0c\u9009\u62e9\u5408\u9002\u7684Python\u5e93\u81f3\u5173\u91cd\u8981\u3002\u5e38\u7528\u7684\u5e93\u5305\u62ecBeautiful Soup\u3001Scrapy\u548cRequests\u3002Beautiful Soup\u7528\u4e8e\u89e3\u6790HTML\u6587\u6863\uff0c\u9002\u5408\u5c0f\u89c4\u6a21\u722c\u866b\uff1bScrapy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6846\u67b6\uff0c\u9002\u5408\u5927\u89c4\u6a21\u6570\u636e\u6293\u53d6\uff1bRequests\u5219\u7528\u4e8e\u53d1\u9001\u7f51\u7edc\u8bf7\u6c42\uff0c\u7b80\u5355\u6613\u7528\u3002\u6839\u636e\u9879\u76ee\u9700\u6c42\uff0c\u5408\u7406\u9009\u62e9\u5e93\u53ef\u4ee5\u63d0\u9ad8\u722c\u53d6\u6548\u7387\u548c\u4ee3\u7801\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<p><strong>\u5728\u722c\u53d6\u5546\u54c1\u6570\u636e\u65f6\uff0c\u5982\u4f55\u5904\u7406\u53cd\u722c\u866b\u673a\u5236\uff1f<\/strong><br \/>\u8bb8\u591a\u7535\u5546\u7f51\u7ad9\u5b9e\u65bd\u53cd\u722c\u866b\u673a\u5236\u4ee5\u4fdd\u62a4\u6570\u636e\u3002\u4e3a\u4e86\u6709\u6548\u5e94\u5bf9\u8fd9\u4e9b\u63aa\u65bd\uff0c\u53ef\u4ee5\u91c7\u7528\u4e0d\u540c\u7684\u7b56\u7565\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u4ee3\u7406IP\u6765\u9690\u85cf\u771f\u5b9eIP\u5730\u5740\u3001\u8bbe\u7f6e\u8bf7\u6c42\u5934\u6a21\u62df\u6d4f\u89c8\u5668\u884c\u4e3a\u3001\u4f7f\u7528\u968f\u673a\u65f6\u95f4\u95f4\u9694\u53d1\u9001\u8bf7\u6c42\u7b49\u3002\u6b64\u5916\uff0c\u8003\u8651\u4f7f\u7528\u722c\u866b\u6846\u67b6\u4e2d\u7684\u4e2d\u95f4\u4ef6\u529f\u80fd\uff0c\u5e2e\u52a9\u5904\u7406\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u53d8\u5316\u3002<\/p>\n<p><strong>\u5982\u4f55\u786e\u4fdd\u722c\u53d6\u5230\u7684\u6570\u636e\u7684\u51c6\u786e\u6027\u548c\u5b8c\u6574\u6027\uff1f<\/strong><br \/>\u786e\u4fdd\u722c\u53d6\u6570\u636e\u7684\u51c6\u786e\u6027\u548c\u5b8c\u6574\u6027\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u3002\u9996\u5148\uff0c\u8fdb\u884c\u6570\u636e\u53bb\u91cd\uff0c\u907f\u514d\u91cd\u590d\u6570\u636e\u7684\u51fa\u73b0\u3002\u5176\u6b21\uff0c\u8bbe\u7f6e\u9002\u5f53\u7684\u722c\u53d6\u9891\u7387\uff0c\u907f\u514d\u56e0\u8fc7\u4e8e\u9891\u7e41\u7684\u8bf7\u6c42\u5bfc\u81f4\u6570\u636e\u4e0d\u5b8c\u6574\u6216\u88ab\u5c01\u7981\u3002\u6b64\u5916\uff0c\u5b9a\u671f\u5bf9\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u548c\u6821\u9a8c\uff0c\u786e\u4fdd\u6570\u636e\u683c\u5f0f\u4e00\u81f4\u5e76\u7b26\u5408\u9884\u671f\u6807\u51c6\uff0c\u4e5f\u80fd\u5927\u5927\u63d0\u5347\u6570\u636e\u8d28\u91cf\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u722c\u53d6\u5546\u54c1\u7684\u5173\u952e\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u5408\u9002\u7684\u5e93\u3001\u83b7\u53d6\u76ee\u6807\u7f51\u9875\u7684URL\u3001\u89e3\u6790\u7f51\u9875\u6570\u636e\u3001\u5b58\u50a8\u6570\u636e\u3002\u5176\u4e2d\uff0c\u9009\u62e9 [&hellip;]","protected":false},"author":3,"featured_media":1174040,"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\/1174037"}],"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=1174037"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1174037\/revisions"}],"predecessor-version":[{"id":1174041,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1174037\/revisions\/1174041"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1174040"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1174037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1174037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1174037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}