{"id":158347,"date":"2024-11-03T01:04:27","date_gmt":"2024-11-02T17:04:27","guid":{"rendered":"https:\/\/server.hk\/cnblog\/158347\/"},"modified":"2024-11-03T01:04:29","modified_gmt":"2024-11-02T17:04:29","slug":"%e9%ab%98%e6%95%88%e5%af%a6%e7%94%a8%e7%9a%84%e6%96%b0%e8%81%9e%e6%8a%93%e5%8f%96%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%8c%e8%ae%93%e4%bd%a0%e5%8f%8a%e6%99%82%e6%8e%8c%e6%8f%a1%e5%85%a8%e7%90%83%e6%9c%80","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/158347\/","title":{"rendered":"\u9ad8\u6548\u5be6\u7528\u7684\u65b0\u805e\u6293\u53d6\u6578\u64da\u5eab\uff0c\u8b93\u4f60\u53ca\u6642\u638c\u63e1\u5168\u7403\u6700\u65b0\u8cc7\u8a0a\uff08\u65b0\u805e\u6293\u53d6\u6578\u64da\u5eab\uff09"},"content":{"rendered":"<h1 id=\"%e9%ab%98%e6%95%88%e5%af%a6%e7%94%a8%e7%9a%84%e6%96%b0%e8%81%9e%e6%8a%93%e5%8f%96%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%8c%e8%ae%93%e4%bd%a0%e5%8f%8a%e6%99%82%e6%8e%8c%e6%8f%a1%e5%85%a8%e7%90%83%e6%9c%80-DxWXlPWmpu\">\u9ad8\u6548\u5be6\u7528\u7684\u65b0\u805e\u6293\u53d6\u6578\u64da\u5eab\uff0c\u8b93\u4f60\u53ca\u6642\u638c\u63e1\u5168\u7403\u6700\u65b0\u8cc7\u8a0a\uff08\u65b0\u805e\u6293\u53d6\u6578\u64da\u5eab\uff09<\/h1>\n<p>\u5728\u7576\u4eca\u4fe1\u606f\u7206\u70b8\u7684\u6642\u4ee3\uff0c\u53ca\u6642\u7372\u53d6\u6700\u65b0\u7684\u65b0\u805e\u8cc7\u8a0a\u5c0d\u65bc\u500b\u4eba\u548c\u4f01\u696d\u4f86\u8aaa\u90fd\u81f3\u95dc\u91cd\u8981\u3002\u65b0\u805e\u6293\u53d6\u6578\u64da\u5eab\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u6578\u64da\u6536\u96c6\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u7528\u6236\u81ea\u52d5\u5316\u5730\u5f9e\u5404\u5927\u65b0\u805e\u7db2\u7ad9\u548c\u793e\u4ea4\u5a92\u9ad4\u5e73\u53f0\u4e2d\u63d0\u53d6\u4fe1\u606f\uff0c\u5f9e\u800c\u5be6\u73fe\u5feb\u901f\u3001\u6e96\u78ba\u7684\u8cc7\u8a0a\u66f4\u65b0\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e6%96%b0%e8%81%9e%e6%8a%93%e5%8f%96%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-DxWXlPWmpu\">\u4ec0\u9ebc\u662f\u65b0\u805e\u6293\u53d6\u6578\u64da\u5eab\uff1f<\/h2>\n<p>\u65b0\u805e\u6293\u53d6\u6578\u64da\u5eab\u662f\u4e00\u7a2e\u5c08\u9580\u8a2d\u8a08\u7528\u4f86\u6536\u96c6\u548c\u5b58\u5132\u65b0\u805e\u6578\u64da\u7684\u7cfb\u7d71\u3002\u5b83\u901a\u5e38\u5305\u62ec\u4e00\u500b\u722c\u87f2\u7a0b\u5e8f\uff0c\u9019\u4e9b\u7a0b\u5e8f\u80fd\u5920\u81ea\u52d5\u8a2a\u554f\u7279\u5b9a\u7684\u7db2\u7ad9\uff0c\u63d0\u53d6\u6240\u9700\u7684\u6578\u64da\uff0c\u4e26\u5c07\u5176\u5b58\u5132\u5728\u6578\u64da\u5eab\u4e2d\u3002\u9019\u4e9b\u6578\u64da\u53ef\u4ee5\u5305\u62ec\u65b0\u805e\u6a19\u984c\u3001\u5167\u5bb9\u3001\u767c\u5e03\u6642\u9593\u3001\u4f86\u6e90\u7b49\u4fe1\u606f\u3002<\/p>\n<h2 id=\"%e6%96%b0%e8%81%9e%e6%8a%93%e5%8f%96%e7%9a%84%e5%b7%a5%e4%bd%9c%e5%8e%9f%e7%90%86-DxWXlPWmpu\">\u65b0\u805e\u6293\u53d6\u7684\u5de5\u4f5c\u539f\u7406<\/h2>\n<p>\u65b0\u805e\u6293\u53d6\u7684\u904e\u7a0b\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li><strong>\u9078\u64c7\u76ee\u6a19\u7db2\u7ad9\uff1a<\/strong>\u78ba\u5b9a\u9700\u8981\u6293\u53d6\u7684\u65b0\u805e\u7db2\u7ad9\u6216\u793e\u4ea4\u5a92\u9ad4\u5e73\u53f0\u3002<\/li>\n<li><strong>\u8a2d\u8a08\u722c\u87f2\uff1a<\/strong>\u4f7f\u7528\u7de8\u7a0b\u8a9e\u8a00\uff08\u5982Python\uff09\u7de8\u5beb\u722c\u87f2\u7a0b\u5e8f\uff0c\u8a2d\u7f6e\u6293\u53d6\u898f\u5247\u3002<\/li>\n<li><strong>\u6578\u64da\u63d0\u53d6\uff1a<\/strong>\u722c\u87f2\u81ea\u52d5\u8a2a\u554f\u7db2\u7ad9\uff0c\u63d0\u53d6\u6240\u9700\u7684\u6578\u64da\u3002<\/li>\n<li><strong>\u6578\u64da\u5b58\u5132\uff1a<\/strong>\u5c07\u63d0\u53d6\u7684\u6578\u64da\u5b58\u5132\u5230\u6578\u64da\u5eab\u4e2d\uff0c\u65b9\u4fbf\u5f8c\u7e8c\u67e5\u8a62\u548c\u5206\u6790\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%96%b0%e8%81%9e%e6%8a%93%e5%8f%96%e7%9a%84%e6%8a%80%e8%a1%93%e5%af%a6%e7%8f%be-DxWXlPWmpu\">\u65b0\u805e\u6293\u53d6\u7684\u6280\u8853\u5be6\u73fe<\/h2>\n<p>\u5728\u6280\u8853\u5be6\u73fe\u65b9\u9762\uff0cPython\u662f\u4e00\u7a2e\u975e\u5e38\u6d41\u884c\u7684\u9078\u64c7\uff0c\u56e0\u70ba\u5b83\u64c1\u6709\u5f37\u5927\u7684\u5eab\u652f\u6301\uff0c\u5982BeautifulSoup\u548cScrapy\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528BeautifulSoup\u9032\u884c\u65b0\u805e\u6293\u53d6\uff1a<\/p>\n<pre><code>import requests\nfrom bs4 import BeautifulSoup\n\n# \u8a2d\u5b9a\u76ee\u6a19\u7db2\u5740\nurl = 'https:\/\/example.com\/news'\n\n# \u767c\u9001\u8acb\u6c42\nresponse = requests.get(url)\n\n# \u89e3\u6790HTML\nsoup = BeautifulSoup(response.text, 'html.parser')\n\n# \u63d0\u53d6\u65b0\u805e\u6a19\u984c\nfor title in soup.find_all('h2', class_='news-title'):\n    print(title.get_text())\n<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u9996\u5148\u767c\u9001\u4e00\u500bHTTP\u8acb\u6c42\u5230\u6307\u5b9a\u7684\u65b0\u805e\u7db2\u7ad9\uff0c\u7136\u5f8c\u4f7f\u7528BeautifulSoup\u89e3\u6790\u8fd4\u56de\u7684HTML\u5167\u5bb9\uff0c\u6700\u5f8c\u63d0\u53d6\u4e26\u6253\u5370\u51fa\u6240\u6709\u65b0\u805e\u6a19\u984c\u3002<\/p>\n<h2 id=\"%e6%96%b0%e8%81%9e%e6%8a%93%e5%8f%96%e7%9a%84%e6%87%89%e7%94%a8%e5%a0%b4%e6%99%af-DxWXlPWmpu\">\u65b0\u805e\u6293\u53d6\u7684\u61c9\u7528\u5834\u666f<\/h2>\n<p>\u65b0\u805e\u6293\u53d6\u6578\u64da\u5eab\u7684\u61c9\u7528\u5834\u666f\u975e\u5e38\u5ee3\u6cdb\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u65bc\uff1a<\/p>\n<ul>\n<li><strong>\u5e02\u5834\u5206\u6790\uff1a<\/strong>\u4f01\u696d\u53ef\u4ee5\u901a\u904e\u6293\u53d6\u884c\u696d\u65b0\u805e\uff0c\u4e86\u89e3\u5e02\u5834\u52d5\u614b\u548c\u7af6\u722d\u5c0d\u624b\u7684\u52d5\u5411\u3002<\/li>\n<li><strong>\u8f3f\u60c5\u76e3\u6e2c\uff1a<\/strong>\u653f\u5e9c\u548c\u516c\u5171\u6a5f\u69cb\u53ef\u4ee5\u76e3\u6e2c\u793e\u6703\u8f3f\u8ad6\uff0c\u53ca\u6642\u61c9\u5c0d\u6c11\u773e\u95dc\u6ce8\u7684\u71b1\u9ede\u554f\u984c\u3002<\/li>\n<li><strong>\u5167\u5bb9\u805a\u5408\uff1a<\/strong>\u65b0\u805e\u805a\u5408\u7db2\u7ad9\u53ef\u4ee5\u901a\u904e\u6293\u53d6\u591a\u500b\u4f86\u6e90\u7684\u65b0\u805e\uff0c\u63d0\u4f9b\u66f4\u5168\u9762\u7684\u8cc7\u8a0a\u670d\u52d9\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%b3%95%e5%be%8b%e8%88%87%e9%81%93%e5%be%b7%e8%80%83%e9%87%8f-DxWXlPWmpu\">\u6cd5\u5f8b\u8207\u9053\u5fb7\u8003\u91cf<\/h2>\n<p>\u5728\u9032\u884c\u65b0\u805e\u6293\u53d6\u6642\uff0c\u5fc5\u9808\u9075\u5faa\u76f8\u95dc\u6cd5\u5f8b\u6cd5\u898f\u548c\u9053\u5fb7\u6e96\u5247\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\u4e26\u9075\u5b88\u9019\u4e9b\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\u3001\u54ea\u4e9b\u9801\u9762\u4e0d\u53ef\u4ee5\u6293\u53d6\u7684\u6a19\u6e96\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-DxWXlPWmpu\">\u7e3d\u7d50<\/h2>\n<p>\u65b0\u805e\u6293\u53d6\u6578\u64da\u5eab\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u7528\u6236\u53ca\u6642\u638c\u63e1\u5168\u7403\u6700\u65b0\u8cc7\u8a0a\u3002\u901a\u904e\u81ea\u52d5\u5316\u7684\u6578\u64da\u6536\u96c6\u904e\u7a0b\uff0c\u7528\u6236\u53ef\u4ee5\u66f4\u9ad8\u6548\u5730\u7372\u53d6\u6240\u9700\u7684\u4fe1\u606f\uff0c\u4e26\u5728\u6b64\u57fa\u790e\u4e0a\u9032\u884c\u6df1\u5165\u5206\u6790\u3002\u96a8\u8457\u6280\u8853\u7684\u9032\u6b65\uff0c\u65b0\u805e\u6293\u53d6\u7684\u61c9\u7528\u5c07\u6703\u8d8a\u4f86\u8d8a\u5ee3\u6cdb\uff0c\u6210\u70ba\u4fe1\u606f\u6642\u4ee3\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u5982\u679c\u4f60\u9700\u8981\u7a69\u5b9a\u7684\u6578\u64da\u5b58\u5132\u548c\u8655\u7406\u80fd\u529b\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u6216<a href=\"https:\/\/server.hk\">\u4e91\u670d\u52a1\u5668<\/a>\u4f86\u652f\u6301\u4f60\u7684\u65b0\u805e\u6293\u53d6\u9805\u76ee\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9ad8\u6548\u5be6\u7528\u7684\u65b0\u805e\u6293\u53d6\u6578\u64da\u5eab\uff0c\u52a9\u4f60\u5373\u6642\u638c\u63e1\u5168\u7403\u6700\u65b0\u8cc7\u8a0a\uff0c\u96a8\u6642\u96a8\u5730\u7372\u53d6\u91cd\u8981\u65b0\u805e\u52d5\u614b\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-158347","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/158347","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=158347"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/158347\/revisions"}],"predecessor-version":[{"id":158348,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/158347\/revisions\/158348"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=158347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=158347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=158347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}