{"id":937633,"date":"2024-12-26T19:55:41","date_gmt":"2024-12-26T11:55:41","guid":{"rendered":""},"modified":"2024-12-26T19:55:43","modified_gmt":"2024-12-26T11:55:43","slug":"python%e5%a6%82%e4%bd%95%e7%88%ac%e7%bd%91%e9%a1%b5","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/937633.html","title":{"rendered":"python\u5982\u4f55\u722c\u7f51\u9875"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25073416\/51df2038-6519-46ca-aaa8-71412b150c42.webp\" alt=\"python\u5982\u4f55\u722c\u7f51\u9875\" \/><\/p>\n<p><p> <strong>Python\u722c\u7f51\u9875\u7684\u5e38\u7528\u65b9\u6cd5\u6709\u4f7f\u7528requests\u5e93\u8fdb\u884cHTTP\u8bf7\u6c42\u3001\u5229\u7528BeautifulSoup\u89e3\u6790HTML\u3001\u4ee5\u53ca\u501f\u52a9Selenium\u8fdb\u884c\u52a8\u6001\u9875\u9762\u6293\u53d6\u3002<\/strong> \u5176\u4e2d\uff0c<strong>requests<\/strong>\u5e93\u662f\u6700\u5e38\u7528\u7684\uff0c\u5b83\u53ef\u4ee5\u53d1\u9001HTTP\u8bf7\u6c42\u5e76\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\uff1b<strong>BeautifulSoup<\/strong>\u5219\u7528\u4e8e\u89e3\u6790\u548c\u63d0\u53d6HTML\u4e2d\u7684\u6570\u636e\uff1b\u800c\u5bf9\u4e8eJavaScript\u52a8\u6001\u751f\u6210\u7684\u9875\u9762\u5185\u5bb9\uff0c<strong>Selenium<\/strong>\u53ef\u4ee5\u6a21\u62df\u6d4f\u89c8\u5668\u7684\u884c\u4e3a\u6765\u6293\u53d6\u6570\u636e\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5229\u7528\u8fd9\u4e9b\u5de5\u5177\u8fdb\u884c\u7f51\u9875\u722c\u53d6\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528REQUESTS\u5e93\u8fdb\u884cHTTP\u8bf7\u6c42<\/p>\n<\/p>\n<p><p>requests\u5e93\u662fPython\u4e2d\u7528\u4e8e\u53d1\u9001HTTP\u8bf7\u6c42\u7684\u7b80\u4fbf\u5de5\u5177\u3002\u5b83\u652f\u6301GET\u3001POST\u7b49\u591a\u79cdHTTP\u65b9\u6cd5\uff0c\u4f7f\u7528\u8d77\u6765\u5341\u5206\u7b80\u5355\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5\u548c\u57fa\u7840\u4f7f\u7528<\/strong><\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5requests\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\u8fdb\u884c\u57fa\u672c\u7684HTTP\u8bf7\u6c42\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>url = &#39;https:\/\/example.com&#39;<\/p>\n<p>response = requests.get(url)<\/p>\n<p>if response.status_code == 200:<\/p>\n<p>    print(&quot;Request was successful!&quot;)<\/p>\n<p>    print(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 the page. Status code: {response.status_code}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>requests.get()<\/code>\u65b9\u6cd5\u53d1\u9001\u4e00\u4e2aGET\u8bf7\u6c42\uff0c\u5e76\u68c0\u67e5\u54cd\u5e94\u7684\u72b6\u6001\u7801\u662f\u5426\u4e3a200\uff08\u5373\u8bf7\u6c42\u6210\u529f\uff09\u3002<code>response.text<\/code>\u5305\u542b\u4e86\u7f51\u9875\u7684HTML\u5185\u5bb9\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5904\u7406\u8bf7\u6c42\u5934\u548c\u53c2\u6570<\/strong><\/li>\n<\/ol>\n<p><p>\u6709\u65f6\uff0c\u6211\u4eec\u9700\u8981\u5728\u8bf7\u6c42\u4e2d\u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u8bf7\u6c42\u5934\u6216\u8005\u53c2\u6570\u3002\u4f8b\u5982\uff0c\u6a21\u62df\u6d4f\u89c8\u5668\u8bf7\u6c42\u6216\u8005\u4f20\u9012\u67e5\u8be2\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">headers = {&#39;User-Agent&#39;: &#39;Mozilla\/5.0&#39;}<\/p>\n<p>params = {&#39;q&#39;: &#39;python&#39;}<\/p>\n<p>response = requests.get(url, headers=headers, params=params)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7<code>headers<\/code>\u53c2\u6570\u6a21\u62df\u4e86\u4e00\u4e2a\u6d4f\u89c8\u5668\u7684\u8bf7\u6c42\u5934\uff0c\u5e76\u901a\u8fc7<code>params<\/code>\u53c2\u6570\u4f20\u9012\u4e86\u67e5\u8be2\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5229\u7528BEAUTIFULSOUP\u89e3\u6790HTML<\/p>\n<\/p>\n<p><p>\u5728\u83b7\u53d6\u4e86\u7f51\u9875\u7684HTML\u5185\u5bb9\u540e\uff0c\u6211\u4eec\u9700\u8981\u89e3\u6790\u5b83\u4ee5\u63d0\u53d6\u51fa\u6709\u7528\u7684\u6570\u636e\u3002BeautifulSoup\u662f\u4e00\u4e2a\u7528\u4e8e\u89e3\u6790HTML\u548cXML\u7684Python\u5e93\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5\u548c\u57fa\u672c\u7528\u6cd5<\/strong><\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u5b89\u88c5BeautifulSoup\u548c\u89e3\u6790\u5668lxml\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install beautifulsoup4 lxml<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\u89e3\u6790HTML\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from bs4 import BeautifulSoup<\/p>\n<p>html_doc = response.text<\/p>\n<p>soup = BeautifulSoup(html_doc, &#39;lxml&#39;)<\/p>\n<h2><strong>\u63d0\u53d6\u6240\u6709\u7684\u6807\u9898\u6807\u7b7e<\/strong><\/h2>\n<p>titles = soup.find_all(&#39;h1&#39;)<\/p>\n<p>for title in titles:<\/p>\n<p>    print(title.get_text())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2aBeautifulSoup\u5bf9\u8c61\uff0c\u5e76\u4f7f\u7528<code>find_all<\/code>\u65b9\u6cd5\u67e5\u627e\u6240\u6709\u7684<code>&lt;h1&gt;<\/code>\u6807\u7b7e\uff0c\u7136\u540e\u63d0\u53d6\u5e76\u6253\u5370\u5176\u6587\u672c\u5185\u5bb9\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528CSS\u9009\u62e9\u5668<\/strong><\/li>\n<\/ol>\n<p><p>BeautifulSoup\u8fd8\u652f\u6301\u4f7f\u7528CSS\u9009\u62e9\u5668\u6765\u67e5\u627e\u5143\u7d20\uff0c\u8fd9\u5bf9\u4e8e\u590d\u6742\u7684HTML\u7ed3\u6784\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528CSS\u9009\u62e9\u5668\u67e5\u627e<\/p>\n<p>titles = soup.select(&#39;h1.title&#39;)<\/p>\n<p>for title in titles:<\/p>\n<p>    print(title.get_text())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>select<\/code>\u65b9\u6cd5\u5141\u8bb8\u6211\u4eec\u4f7f\u7528\u7c7b\u4f3c\u4e8eCSS\u7684\u8bed\u6cd5\u6765\u9009\u62e9\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528SELENIUM\u6293\u53d6\u52a8\u6001\u9875\u9762<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u901a\u8fc7JavaScript\u52a8\u6001\u52a0\u8f7d\u5185\u5bb9\u7684\u7f51\u9875\uff0crequests\u548cBeautifulSoup\u53ef\u80fd\u65e0\u6cd5\u76f4\u63a5\u83b7\u53d6\u5230\u6240\u9700\u7684\u6570\u636e\u3002\u8fd9\u65f6\u53ef\u4ee5\u4f7f\u7528Selenium\uff0c\u5b83\u53ef\u4ee5\u81ea\u52a8\u5316\u6d4f\u89c8\u5668\u64cd\u4f5c\uff0c\u4ece\u800c\u6a21\u62df\u7528\u6237\u7684\u884c\u4e3a\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5\u548c\u57fa\u672c\u4f7f\u7528<\/strong><\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u5b89\u88c5Selenium\u548c\u5bf9\u5e94\u7684WebDriver\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\u4e0b\u8f7d\u9002\u7528\u4e8e\u4f60\u6d4f\u89c8\u5668\u7248\u672c\u7684WebDriver\uff0c\u5e76\u786e\u4fdd\u5b83\u5728\u4f60\u7684PATH\u4e2d\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\u662f\u4e00\u4e2a\u4f7f\u7528Selenium\u6293\u53d6\u9875\u9762\u7684\u57fa\u672c\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium import webdriver<\/p>\n<p>driver = webdriver.Chrome()<\/p>\n<p>driver.get(&#39;https:\/\/example.com&#39;)<\/p>\n<h2><strong>\u7b49\u5f85\u9875\u9762\u52a0\u8f7d\u5b8c\u6210<\/strong><\/h2>\n<p>driver.implicitly_wait(10)<\/p>\n<h2><strong>\u63d0\u53d6\u9875\u9762\u6570\u636e<\/strong><\/h2>\n<p>content = driver.page_source<\/p>\n<p>print(content)<\/p>\n<p>driver.quit()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521d\u59cb\u5316\u4e86\u4e00\u4e2aChrome\u6d4f\u89c8\u5668\u5b9e\u4f8b\uff0c\u6253\u5f00\u4e86\u6307\u5b9a\u7684URL\uff0c\u5e76\u5728\u9875\u9762\u52a0\u8f7d\u5b8c\u6210\u540e\u63d0\u53d6HTML\u6e90\u4ee3\u7801\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6a21\u62df\u7528\u6237\u64cd\u4f5c<\/strong><\/li>\n<\/ol>\n<p><p>Selenium\u8fd8\u53ef\u4ee5\u6a21\u62df\u7528\u6237\u7684\u5404\u79cd\u64cd\u4f5c\uff0c\u5982\u70b9\u51fb\u3001\u8f93\u5165\u6587\u672c\u7b49\uff0c\u8fd9\u5728\u9700\u8981\u767b\u5f55\u6216\u8005\u8fdb\u884c\u590d\u6742\u4ea4\u4e92\u7684\u573a\u666f\u4e0b\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium.webdriver.common.by import By<\/p>\n<p>from selenium.webdriver.common.keys import Keys<\/p>\n<h2><strong>\u627e\u5230\u8f93\u5165\u6846\u5e76\u8f93\u5165\u6587\u672c<\/strong><\/h2>\n<p>search_box = driver.find_element(By.NAME, &#39;q&#39;)<\/p>\n<p>search_box.send_keys(&#39;Python&#39; + Keys.RETURN)<\/p>\n<h2><strong>\u7b49\u5f85\u641c\u7d22\u7ed3\u679c\u52a0\u8f7d<\/strong><\/h2>\n<p>driver.implicitly_wait(10)<\/p>\n<h2><strong>\u63d0\u53d6\u641c\u7d22\u7ed3\u679c<\/strong><\/h2>\n<p>results = driver.find_elements(By.CSS_SELECTOR, &#39;h3&#39;)<\/p>\n<p>for result in results:<\/p>\n<p>    print(result.text)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u6a21\u62df\u4e86\u5728\u641c\u7d22\u6846\u4e2d\u8f93\u5165\u6587\u672c\u5e76\u6309\u4e0b\u56de\u8f66\u952e\uff0c\u968f\u540e\u6293\u53d6\u5e76\u6253\u5370\u4e86\u641c\u7d22\u7ed3\u679c\u7684\u6807\u9898\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5904\u7406\u53cd\u722c\u866b\u6280\u672f<\/p>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u7f51\u9875\u722c\u53d6\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u53cd\u722c\u866b\u6280\u672f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u5e94\u5bf9\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u6a21\u62df\u4eba\u7c7b\u884c\u4e3a<\/strong><\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u968f\u673a\u5ef6\u65f6\u3001\u6a21\u62df\u9f20\u6807\u79fb\u52a8\u548c\u70b9\u51fb\u7b49\u65b9\u5f0f\uff0c\u4f7f\u8bf7\u6c42\u770b\u8d77\u6765\u66f4\u50cf\u662f\u7531\u4eba\u7c7b\u53d1\u8d77\u7684\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528\u4ee3\u7406IP<\/strong><\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4f7f\u7528\u4ee3\u7406IP\u907f\u514d\u56e0\u9891\u7e41\u8bf7\u6c42\u5bfc\u81f4\u7684IP\u5c01\u7981\u3002\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u7684\u4ee3\u7406\u670d\u52a1\u6216\u8005\u642d\u5efa\u81ea\u5df1\u7684\u4ee3\u7406\u6c60\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u8c03\u6574\u8bf7\u6c42\u5934<\/strong><\/li>\n<\/ol>\n<p><p>\u9002\u5f53\u8c03\u6574\u8bf7\u6c42\u5934\uff0c\u4f7f\u5176\u770b\u8d77\u6765\u66f4\u50cf\u662f\u7531\u6d4f\u89c8\u5668\u53d1\u8d77\u7684\u8bf7\u6c42\uff0c\u5305\u62ecUser-Agent\u3001Referer\u7b49\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u5206\u5e03\u5f0f\u722c\u866b<\/strong><\/li>\n<\/ol>\n<p><p>\u5229\u7528\u5206\u5e03\u5f0f\u722c\u866b\u6280\u672f\uff0c\u5206\u6563\u8bf7\u6c42\uff0c\u907f\u514d\u5bf9\u5355\u4e2a\u670d\u52a1\u5668\u9020\u6210\u8fc7\u5927\u538b\u529b\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u6570\u636e\u5b58\u50a8\u4e0e\u6e05\u6d17<\/p>\n<\/p>\n<p><p>\u5728\u83b7\u53d6\u5230\u9700\u8981\u7684\u6570\u636e\u540e\uff0c\u901a\u5e38\u9700\u8981\u8fdb\u884c\u5b58\u50a8\u548c\u6e05\u6d17\uff0c\u4ee5\u4fbf\u540e\u7eed\u5206\u6790\u548c\u4f7f\u7528\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b58\u50a8\u5230\u6587\u4ef6\u6216\u6570\u636e\u5e93<\/strong><\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u5c06\u6293\u53d6\u7684\u6570\u636e\u5b58\u50a8\u5230CSV\u3001JSON\u7b49\u6587\u4ef6\u4e2d\uff0c\u6216\u8005\u76f4\u63a5\u5b58\u5165\u6570\u636e\u5e93\u5982SQLite\u3001MySQL\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import csv<\/p>\n<p>with open(&#39;data.csv&#39;, &#39;w&#39;, newline=&#39;&#39;, encoding=&#39;utf-8&#39;) as csvfile:<\/p>\n<p>    writer = csv.writer(csvfile)<\/p>\n<p>    writer.writerow([&#39;Title&#39;, &#39;Link&#39;])<\/p>\n<p>    for title, link in zip(titles, links):<\/p>\n<p>        writer.writerow([title, link])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6570\u636e\u6e05\u6d17<\/strong><\/li>\n<\/ol>\n<p><p>\u6570\u636e\u6e05\u6d17\u662f\u6307\u53bb\u9664\u6570\u636e\u4e2d\u7684\u566a\u58f0\u3001\u4fee\u6b63\u9519\u8bef\u3001\u586b\u8865\u7f3a\u5931\u503c\u7b49\u6b65\u9aa4\u3002\u53ef\u4ee5\u4f7f\u7528Pandas\u7b49\u6570\u636e\u5904\u7406\u5e93\u6765\u8fdb\u884c\u6570\u636e\u6e05\u6d17\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>df = pd.read_csv(&#39;data.csv&#39;)<\/p>\n<p>df.dropna(inplace=True)  # \u53bb\u9664\u7a7a\u884c<\/p>\n<p>df[&#39;Title&#39;] = df[&#39;Title&#39;].str.strip()  # \u53bb\u9664\u6807\u9898\u7684\u7a7a\u683c<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u603b\u7ed3\uff0cPython\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\u548c\u5e93\u6765\u8fdb\u884c\u7f51\u9875\u722c\u53d6\u3002\u901a\u8fc7requests\u5e93\u8fdb\u884cHTTP\u8bf7\u6c42\u3001BeautifulSoup\u89e3\u6790HTML\u3001\u4ee5\u53caSelenium\u6293\u53d6\u52a8\u6001\u5185\u5bb9\uff0c\u53ef\u4ee5\u5e94\u5bf9\u7edd\u5927\u591a\u6570\u7684\u7f51\u9875\u722c\u53d6\u9700\u6c42\u3002\u5728\u5b9e\u9645\u64cd\u4f5c\u4e2d\uff0c\u9700\u6ce8\u610f\u5408\u6cd5\u5408\u89c4\u6027\uff0c\u9075\u5faa\u7f51\u7ad9\u7684robots.txt\u534f\u8bae\u548c\u76f8\u5173\u6cd5\u5f8b\u6cd5\u89c4\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\u7f51\u9875\u722c\u53d6\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u6709\u591a\u4e2a\u5e93\u53ef\u4f9b\u9009\u62e9\u4ee5\u8fdb\u884c\u7f51\u9875\u722c\u53d6\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u5305\u62ecBeautiful Soup\u3001Scrapy\u548cRequests\u3002Beautiful Soup\u9002\u5408\u5904\u7406HTML\u548cXML\u6587\u6863\u7684\u89e3\u6790\u548c\u5bfc\u822a\uff0c\u800cRequests\u5e93\u5219\u7528\u4e8e\u53d1\u9001HTTP\u8bf7\u6c42\uff0c\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\u3002Scrapy\u5219\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u6846\u67b6\uff0c\u9002\u5408\u8fdb\u884c\u5927\u578b\u548c\u590d\u6742\u7684\u722c\u866b\u9879\u76ee\u3002\u6839\u636e\u9879\u76ee\u7684\u9700\u6c42\u548c\u590d\u6742\u7a0b\u5ea6\u9009\u62e9\u5408\u9002\u7684\u5e93\u53ef\u4ee5\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n<p><strong>\u5728\u8fdb\u884c\u7f51\u9875\u722c\u53d6\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u6cd5\u5f8b\u548c\u9053\u5fb7\u95ee\u9898\uff1f<\/strong><br \/>\u7f51\u9875\u722c\u53d6\u6d89\u53ca\u5230\u6cd5\u5f8b\u548c\u9053\u5fb7\u7684\u8003\u91cf\u3002\u5728\u5f00\u59cb\u722c\u53d6\u4efb\u4f55\u7f51\u7ad9\u4e4b\u524d\uff0c\u9700\u67e5\u770b\u8be5\u7f51\u7ad9\u7684robots.txt\u6587\u4ef6\uff0c\u4e86\u89e3\u7f51\u7ad9\u7684\u722c\u53d6\u89c4\u5219\u3002\u6b64\u5916\uff0c\u9075\u5faa\u7f51\u7ad9\u7684\u4f7f\u7528\u6761\u6b3e\uff0c\u907f\u514d\u9891\u7e41\u8bf7\u6c42\u5bfc\u81f4\u670d\u52a1\u5668\u8d1f\u62c5\u8fc7\u91cd\uff0c\u7ed9\u7f51\u7ad9\u5e26\u6765\u4e0d\u5fc5\u8981\u7684\u538b\u529b\u3002\u786e\u4fdd\u722c\u53d6\u7684\u6570\u636e\u4e0d\u4fb5\u72af\u4ed6\u4eba\u7684\u7248\u6743\u6216\u9690\u79c1\u6743\uff0c\u9075\u5faa\u6570\u636e\u4fdd\u62a4\u6cd5\u89c4\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u52a8\u6001\u7f51\u9875\u7684\u6570\u636e\u722c\u53d6\uff1f<\/strong><br \/>\u52a8\u6001\u7f51\u9875\u901a\u5e38\u901a\u8fc7JavaScript\u52a0\u8f7d\u6570\u636e\uff0c\u8fd9\u4f7f\u5f97\u4f20\u7edf\u7684\u9759\u6001\u722c\u866b\u96be\u4ee5\u83b7\u53d6\u6240\u9700\u4fe1\u606f\u3002\u5bf9\u4e8e\u8fd9\u7c7b\u7f51\u9875\uff0c\u53ef\u4ee5\u4f7f\u7528Selenium\u7b49\u5de5\u5177\uff0c\u5b83\u80fd\u591f\u6a21\u62df\u7528\u6237\u64cd\u4f5c\uff0c\u81ea\u52a8\u52a0\u8f7d\u9875\u9762\u5185\u5bb9\u3002\u6b64\u5916\uff0c\u4e86\u89e3\u7f51\u9875\u80cc\u540e\u7684API\u4e5f\u662f\u4e00\u4e2a\u6709\u6548\u7684\u7b56\u7565\uff0c\u901a\u8fc7\u76f4\u63a5\u8c03\u7528API\u63a5\u53e3\u83b7\u53d6\u6570\u636e\uff0c\u53ef\u4ee5\u5927\u5e45\u63d0\u9ad8\u6570\u636e\u6293\u53d6\u7684\u6548\u7387\u548c\u51c6\u786e\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u722c\u7f51\u9875\u7684\u5e38\u7528\u65b9\u6cd5\u6709\u4f7f\u7528requests\u5e93\u8fdb\u884cHTTP\u8bf7\u6c42\u3001\u5229\u7528BeautifulSoup\u89e3\u6790HTM [&hellip;]","protected":false},"author":3,"featured_media":937634,"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\/937633"}],"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=937633"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/937633\/revisions"}],"predecessor-version":[{"id":937635,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/937633\/revisions\/937635"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/937634"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=937633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=937633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=937633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}