{"id":152695,"date":"2024-11-02T01:15:21","date_gmt":"2024-11-01T17:15:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/152695\/"},"modified":"2024-11-02T01:15:22","modified_gmt":"2024-11-01T17:15:22","slug":"%e7%94%a2%e5%93%81%e9%8a%b7%e9%87%8f%e6%95%b8%e6%93%9a%e6%8a%93%e5%8f%96%ef%bc%9a%e6%8a%80%e5%b7%a7%e8%88%87%e6%96%b9%e6%b3%95-%e5%a6%82%e4%bd%95%e6%8a%93%e5%8f%96%e7%94%a2%e5%93%81%e9%8a%b7%e9%87%8f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/152695\/","title":{"rendered":"\u7522\u54c1\u92b7\u91cf\u6578\u64da\u6293\u53d6\uff1a\u6280\u5de7\u8207\u65b9\u6cd5 (\u5982\u4f55\u6293\u53d6\u7522\u54c1\u92b7\u91cf\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e7%94%a2%e5%93%81%e9%8a%b7%e9%87%8f%e6%95%b8%e6%93%9a%e6%8a%93%e5%8f%96%ef%bc%9a%e6%8a%80%e5%b7%a7%e8%88%87%e6%96%b9%e6%b3%95-%e5%a6%82%e4%bd%95%e6%8a%93%e5%8f%96%e7%94%a2%e5%93%81%e9%8a%b7%e9%87%8f-CHSNrwxaOz\">\u7522\u54c1\u92b7\u91cf\u6578\u64da\u6293\u53d6\uff1a\u6280\u5de7\u8207\u65b9\u6cd5 (\u5982\u4f55\u6293\u53d6\u7522\u54c1\u92b7\u91cf\u6578\u64da\u5eab)<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u5546\u696d\u74b0\u5883\u4e2d\uff0c\u7522\u54c1\u92b7\u91cf\u6578\u64da\u7684\u6293\u53d6\u6210\u70ba\u4f01\u696d\u5236\u5b9a\u5e02\u5834\u7b56\u7565\u7684\u91cd\u8981\u5de5\u5177\u3002\u900f\u904e\u6709\u6548\u7684\u6578\u64da\u6293\u53d6\u6280\u8853\uff0c\u4f01\u696d\u80fd\u5920\u7372\u5f97\u7af6\u722d\u512a\u52e2\uff0c\u4e86\u89e3\u5e02\u5834\u8da8\u52e2\uff0c\u4e26\u505a\u51fa\u66f4\u660e\u667a\u7684\u6c7a\u7b56\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u7522\u54c1\u92b7\u91cf\u6578\u64da\u6293\u53d6\u7684\u6280\u5de7\u8207\u65b9\u6cd5\uff0c\u5e6b\u52a9\u8b80\u8005\u638c\u63e1\u9019\u4e00\u91cd\u8981\u6280\u80fd\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e7%94%a2%e5%93%81%e9%8a%b7%e9%87%8f%e6%95%b8%e6%93%9a%e6%8a%93%e5%8f%96%ef%bc%9f-CHSNrwxaOz\">\u4ec0\u9ebc\u662f\u7522\u54c1\u92b7\u91cf\u6578\u64da\u6293\u53d6\uff1f<\/h2>\n<p>\u7522\u54c1\u92b7\u91cf\u6578\u64da\u6293\u53d6\u662f\u6307\u5f9e\u5404\u7a2e\u4f86\u6e90\uff08\u5982\u96fb\u5b50\u5546\u52d9\u7db2\u7ad9\u3001\u793e\u4ea4\u5a92\u9ad4\u3001\u6578\u64da\u5eab\u7b49\uff09\u81ea\u52d5\u63d0\u53d6\u7522\u54c1\u92b7\u91cf\u76f8\u95dc\u6578\u64da\u7684\u904e\u7a0b\u3002\u9019\u4e9b\u6578\u64da\u901a\u5e38\u5305\u62ec\u92b7\u552e\u6578\u91cf\u3001\u50f9\u683c\u3001\u5eab\u5b58\u72c0\u614b\u3001\u9867\u5ba2\u8a55\u50f9\u7b49\uff0c\u5c0d\u65bc\u5e02\u5834\u5206\u6790\u548c\u5546\u696d\u6c7a\u7b56\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<h2 id=\"%e6%8a%93%e5%8f%96%e7%94%a2%e5%93%81%e9%8a%b7%e9%87%8f%e6%95%b8%e6%93%9a%e7%9a%84%e6%8a%80%e5%b7%a7-CHSNrwxaOz\">\u6293\u53d6\u7522\u54c1\u92b7\u91cf\u6578\u64da\u7684\u6280\u5de7<\/h2>\n<h3 id=\"1-%e7%a2%ba%e5%ae%9a%e6%95%b8%e6%93%9a%e4%be%86%e6%ba%90-CHSNrwxaOz\">1. \u78ba\u5b9a\u6578\u64da\u4f86\u6e90<\/h3>\n<p>\u9996\u5148\uff0c\u4f01\u696d\u9700\u8981\u78ba\u5b9a\u8981\u6293\u53d6\u7684\u6578\u64da\u4f86\u6e90\u3002\u5e38\u898b\u7684\u6578\u64da\u4f86\u6e90\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u96fb\u5b50\u5546\u52d9\u5e73\u53f0\uff08\u5982Amazon\u3001eBay\uff09<\/li>\n<li>\u793e\u4ea4\u5a92\u9ad4\uff08\u5982Facebook\u3001Instagram\uff09<\/li>\n<li>\u884c\u696d\u5831\u544a\u548c\u5e02\u5834\u7814\u7a76\u7db2\u7ad9<\/li>\n<\/ul>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8%e7%b6%b2%e9%a0%81%e6%8a%93%e5%8f%96%e5%b7%a5%e5%85%b7-CHSNrwxaOz\">2. \u4f7f\u7528\u7db2\u9801\u6293\u53d6\u5de5\u5177<\/h3>\n<p>\u7db2\u9801\u6293\u53d6\u5de5\u5177\u662f\u81ea\u52d5\u63d0\u53d6\u7db2\u9801\u6578\u64da\u7684\u8edf\u4ef6\u3002\u5e38\u898b\u7684\u5de5\u5177\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>Beautiful Soup<\/strong>\uff1a\u4e00\u500bPython\u5eab\uff0c\u7528\u65bc\u89e3\u6790HTML\u548cXML\u6587\u6a94\uff0c\u9069\u5408\u521d\u5b78\u8005\u4f7f\u7528\u3002<\/li>\n<li><strong>Scrapy<\/strong>\uff1a\u4e00\u500b\u5f37\u5927\u7684Python\u6846\u67b6\uff0c\u9069\u5408\u9032\u884c\u5927\u898f\u6a21\u7684\u6578\u64da\u6293\u53d6\u3002<\/li>\n<li><strong>Octoparse<\/strong>\uff1a\u4e00\u500b\u7121\u9700\u7de8\u7a0b\u7684\u53ef\u8996\u5316\u6293\u53d6\u5de5\u5177\uff0c\u9069\u5408\u975e\u6280\u8853\u7528\u6236\u3002<\/li>\n<\/ul>\n<h3 id=\"3-%e7%b7%a8%e5%af%ab%e6%8a%93%e5%8f%96%e8%85%b3%e6%9c%ac-CHSNrwxaOz\">3. \u7de8\u5beb\u6293\u53d6\u8173\u672c<\/h3>\n<p>\u5c0d\u65bc\u6709\u7de8\u7a0b\u57fa\u790e\u7684\u7528\u6236\uff0c\u53ef\u4ee5\u7de8\u5beb\u81ea\u5b9a\u7fa9\u7684\u6293\u53d6\u8173\u672c\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528Python\u548cBeautiful Soup\u7684\u7c21\u55ae\u793a\u4f8b\uff1a<\/p>\n<pre><code>import requests\nfrom bs4 import BeautifulSoup\n\nurl = 'https:\/\/example.com\/products'\nresponse = requests.get(url)\nsoup = BeautifulSoup(response.text, 'html.parser')\n\nfor product in soup.find_all('div', class_='product'):\n    name = product.find('h2').text\n    price = product.find('span', class_='price').text\n    print(f'\u7522\u54c1\u540d\u7a31: {name}, \u50f9\u683c: {price}')\n<\/code><\/pre>\n<h3 id=\"4-%e6%95%b8%e6%93%9a%e6%b8%85%e7%90%86%e8%88%87%e5%88%86%e6%9e%90-CHSNrwxaOz\">4. \u6578\u64da\u6e05\u7406\u8207\u5206\u6790<\/h3>\n<p>\u6293\u53d6\u5230\u7684\u6578\u64da\u5f80\u5f80\u9700\u8981\u9032\u884c\u6e05\u7406\u548c\u683c\u5f0f\u5316\uff0c\u4ee5\u4fbf\u9032\u884c\u5f8c\u7e8c\u5206\u6790\u3002\u53ef\u4ee5\u4f7f\u7528Pandas\u7b49\u6578\u64da\u8655\u7406\u5eab\u4f86\u9032\u884c\u6578\u64da\u6e05\u7406\u548c\u5206\u6790\u3002<\/p>\n<pre><code>import pandas as pd\n\n# \u5047\u8a2d\u6293\u53d6\u7684\u6578\u64da\u5b58\u5132\u5728\u4e00\u500b\u5217\u8868\u4e2d\ndata = [{'name': '\u7522\u54c1A', 'price': '100'}, {'name': '\u7522\u54c1B', 'price': '200'}]\ndf = pd.DataFrame(data)\n\n# \u5c07\u50f9\u683c\u8f49\u63db\u70ba\u6578\u5b57\u985e\u578b\ndf['price'] = pd.to_numeric(df['price'])\nprint(df.describe())\n<\/code><\/pre>\n<h2 id=\"%e6%b3%95%e5%be%8b%e8%88%87%e9%81%93%e5%be%b7%e8%80%83%e9%87%8f-CHSNrwxaOz\">\u6cd5\u5f8b\u8207\u9053\u5fb7\u8003\u91cf<\/h2>\n<p>\u5728\u9032\u884c\u6578\u64da\u6293\u53d6\u6642\uff0c\u5fc5\u9808\u9075\u5faa\u6cd5\u5f8b\u548c\u9053\u5fb7\u898f\u7bc4\u3002\u8a31\u591a\u7db2\u7ad9\u5728\u5176\u4f7f\u7528\u689d\u6b3e\u4e2d\u660e\u78ba\u7981\u6b62\u81ea\u52d5\u6293\u53d6\u6578\u64da\uff0c\u56e0\u6b64\u5728\u6293\u53d6\u4e4b\u524d\uff0c\u61c9\u4ed4\u7d30\u95b1\u8b80\u76f8\u95dc\u689d\u6b3e\u3002\u6b64\u5916\uff0c\u61c9\u5c0a\u91cd\u7db2\u7ad9\u7684robots.txt\u6587\u4ef6\uff0c\u9019\u662f\u4e00\u7a2e\u544a\u8a34\u722c\u87f2\u54ea\u4e9b\u9801\u9762\u53ef\u4ee5\u6293\u53d6\u7684\u6a19\u6e96\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-CHSNrwxaOz\">\u7e3d\u7d50<\/h2>\n<p>\u7522\u54c1\u92b7\u91cf\u6578\u64da\u6293\u53d6\u662f\u4e00\u9805\u91cd\u8981\u7684\u6280\u80fd\uff0c\u80fd\u5920\u5e6b\u52a9\u4f01\u696d\u7372\u5f97\u5e02\u5834\u6d1e\u5bdf\u548c\u7af6\u722d\u512a\u52e2\u3002\u901a\u904e\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u4f86\u6e90\u3001\u4f7f\u7528\u6709\u6548\u7684\u6293\u53d6\u5de5\u5177\u3001\u7de8\u5beb\u81ea\u5b9a\u7fa9\u8173\u672c\u4ee5\u53ca\u9032\u884c\u6578\u64da\u6e05\u7406\u8207\u5206\u6790\uff0c\u4f01\u696d\u53ef\u4ee5\u6709\u6548\u5730\u63d0\u53d6\u548c\u5229\u7528\u9019\u4e9b\u6578\u64da\u3002\u5728\u9032\u884c\u6578\u64da\u6293\u53d6\u6642\uff0c\u52d9\u5fc5\u9075\u5faa\u6cd5\u5f8b\u548c\u9053\u5fb7\u898f\u7bc4\uff0c\u4ee5\u78ba\u4fdd\u696d\u52d9\u7684\u53ef\u6301\u7e8c\u767c\u5c55\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5c0d\u65bc\u5982\u4f55\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u6293\u53d6\u9805\u76ee\u611f\u8208\u8da3\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002\u6211\u5011\u63d0\u4f9b\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u5e6b\u52a9\u60a8\u9ad8\u6548\u5730\u9032\u884c\u6578\u64da\u8655\u7406\u548c\u5206\u6790\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u638c\u63e1\u7522\u54c1\u92b7\u91cf\u6578\u64da\u6293\u53d6\u7684\u6280\u5de7\u8207\u65b9\u6cd5\uff0c\u8f15\u9b06\u7372\u53d6\u6578\u64da\u5eab\u8cc7\u8a0a\uff0c\u63d0\u5347\u5e02\u5834\u5206\u6790\u8207\u6c7a\u7b56\u80fd\u529b\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-152695","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=152695"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152695\/revisions"}],"predecessor-version":[{"id":152696,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152695\/revisions\/152696"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=152695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=152695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=152695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}