{"id":177277,"date":"2024-05-08T19:27:53","date_gmt":"2024-05-08T11:27:53","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/177277.html"},"modified":"2024-05-08T19:27:57","modified_gmt":"2024-05-08T11:27:57","slug":"python%e7%88%ac%e8%99%ab%e7%9a%84%e5%bf%85%e5%a4%87%e7%9f%a5%e8%af%86%e6%9c%89%e5%93%aa%e4%ba%9b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/177277.html","title":{"rendered":"python\u722c\u866b\u7684\u5fc5\u5907\u77e5\u8bc6\u6709\u54ea\u4e9b"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27061251\/f93db782-b0f9-4c8a-a049-ed379765f020.webp\" alt=\"python\u722c\u866b\u7684\u5fc5\u5907\u77e5\u8bc6\u6709\u54ea\u4e9b\" \/><\/p>\n<p><p>Python\u722c\u866b\u7684\u5fc5\u5907\u77e5\u8bc6\u4e3b\u8981\u5305\u62ec<strong>HTTP\u534f\u8bae\u7684\u57fa\u7840\u77e5\u8bc6\u3001Python\u7f16\u7a0b\u57fa\u7840\u3001\u6570\u636e\u63d0\u53d6\u4e0e\u89e3\u6790\u65b9\u6cd5\u3001\u722c\u866b\u6846\u67b6\u7684\u4f7f\u7528\u548c\u7406\u89e3\u3001\u6570\u636e\u5b58\u50a8\u65b9\u6cd5<\/strong>\u3001<strong>\u53cd\u722c\u866b\u7b56\u7565\u53ca\u5176\u5e94\u5bf9\u63aa\u65bd<\/strong>\u3002\u5728\u8fd9\u4e9b\u77e5\u8bc6\u4e2d\uff0c<strong>HTTP\u534f\u8bae\u7684\u57fa\u7840\u77e5\u8bc6<\/strong>\u662f\u8fdb\u884c\u7f51\u9875\u6570\u636e\u6293\u53d6\u7684\u524d\u63d0\uff0c\u5b83\u662f\u4e92\u8054\u7f51\u4e2d\u6570\u636e\u4ea4\u6362\u7684\u57fa\u7840\uff0c\u6df1\u5165\u4e86\u89e3HTTP\u534f\u8bae\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u7406\u89e3\u7f51\u9875\u662f\u5982\u4f55\u52a0\u8f7d\u548c\u663e\u793a\u6570\u636e\u7684\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001HTTP\u534f\u8bae\u57fa\u7840<\/p>\n<\/p>\n<p><p>HTTP\uff08\u8d85\u6587\u672c\u4f20\u8f93\u534f\u8bae\uff09\u662f\u7528\u4e8e\u4f20\u8f93\u7f51\u9875\u6570\u636e\u7684\u534f\u8bae\uff0c\u5b83\u5b9a\u4e49\u4e86\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u683c\u5f0f\u3002\u7406\u89e3HTTP\u534f\u8bae\u5bf9\u4e8e\u7f16\u5199\u722c\u866b\u975e\u5e38\u91cd\u8981\uff0c\u56e0\u4e3a\u5927\u90e8\u5206\u7684\u6570\u636e\u6293\u53d6\u6d3b\u52a8\u90fd\u662f\u901a\u8fc7\u53d1\u9001HTTP\u8bf7\u6c42\u548c\u89e3\u6790\u54cd\u5e94\u6765\u5b8c\u6210\u7684\u3002<\/p>\n<\/p>\n<ul>\n<li>\u9996\u5148\uff0c\u4f60\u9700\u8981\u4e86\u89e3HTTP\u8bf7\u6c42\u7684\u57fa\u672c\u7ec4\u6210\u90e8\u5206\uff0c\u5305\u62ec\u8bf7\u6c42\u65b9\u6cd5\uff08\u5982GET\u3001POST\uff09\u3001\u8bf7\u6c42\u5934\u3001\u8bf7\u6c42\u4f53\u7b49\u3002<\/li>\n<li>\u5176\u6b21\uff0c\u7406\u89e3HTTP\u54cd\u5e94\u7684\u7ed3\u6784\u4e5f\u662f\u5fc5\u987b\u7684\uff0c\u4e3b\u8981\u5305\u62ec\u72b6\u6001\u7801\uff08\u5982200\u8868\u793a\u6210\u529f\u3001404\u8868\u793a\u672a\u627e\u5230\u7b49\uff09\u3001\u54cd\u5e94\u5934\u548c\u54cd\u5e94\u4f53\u3002<\/li>\n<\/ul>\n<p><p>\u4e8c\u3001PYTHON\u7f16\u7a0b\u57fa\u7840<\/p>\n<\/p>\n<p><p>\u7f16\u5199\u722c\u866b\u524d\uff0c\u57fa\u7840\u7684Python\u7f16\u7a0b\u77e5\u8bc6\u662f\u5fc5\u987b\u7684\u3002Python\u4ee5\u5176\u7b80\u6d01\u7684\u8bed\u6cd5\u548c\u4e30\u5bcc\u7684\u5e93\u652f\u6301\uff0c\u5728\u722c\u866b\u5f00\u53d1\u4e2d\u5360\u636e\u91cd\u8981\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<ul>\n<li>\u638c\u63e1\u57fa\u672c\u7684\u6570\u636e\u7c7b\u578b\u3001\u6d41\u7a0b\u63a7\u5236\u8bed\u53e5\u3001\u51fd\u6570\u7b49\u57fa\u7840\u7f16\u7a0b\u77e5\u8bc6\u5bf9\u7f16\u5199\u7075\u6d3b\u6709\u6548\u7684\u722c\u866b\u4ee3\u7801\u81f3\u5173\u91cd\u8981\u3002<\/li>\n<li>\u719f\u6089Python\u7684\u7f51\u7edc\u8bf7\u6c42\u5e93\uff0c\u5982requests\uff0c\u4ee5\u53ca\u5176\u4ed6\u8f85\u52a9\u5de5\u5177\u548c\u5e93\uff0c\u6bd4\u5982JSON\u89e3\u6790\u5e93\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u7b49\uff0c\u4e5f\u540c\u6837\u91cd\u8981\u3002<\/li>\n<\/ul>\n<p><p>\u4e09\u3001\u6570\u636e\u63d0\u53d6\u4e0e\u89e3\u6790<\/p>\n<\/p>\n<p><p>\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\u540e\uff0c\u4e0b\u4e00\u6b65\u5c31\u662f\u4ece\u4e2d\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u6570\u636e\u3002\u6570\u636e\u63d0\u53d6\u4e0e\u89e3\u6790\u662f\u722c\u866b\u5f00\u53d1\u4e2d\u7684\u6838\u5fc3\u90e8\u5206\u3002<\/p>\n<\/p>\n<ul>\n<li>\u719f\u6089HTML\u548cCSS\u9009\u62e9\u5668\u662f\u63d0\u53d6\u7f51\u9875\u6570\u636e\u7684\u57fa\u7840\uff0c\u53ef\u4ee5\u5229\u7528BeautifulSoup\u6216lxml\u7b49\u5e93\u6765\u6267\u884c\u8fd9\u4e00\u4efb\u52a1\u3002<\/li>\n<li>\u5b66\u4f1a\u4f7f\u7528XPath\u6216\u6b63\u5219\u8868\u8fbe\u5f0f\u8fdb\u884c\u6570\u636e\u63d0\u53d6\uff0c\u5bf9\u4e8e\u5904\u7406\u590d\u6742\u7684\u7f51\u9875\u7ed3\u6784\u7279\u522b\u6709\u5e2e\u52a9\u3002<\/li>\n<\/ul>\n<p><p>\u56db\u3001\u722c\u866b\u6846\u67b6\u7684\u4f7f\u7528<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u590d\u6742\u7684\u722c\u866b\u9879\u76ee\u6765\u8bf4\uff0c\u76f4\u63a5\u4f7f\u7528\u722c\u866b\u6846\u67b6\u6bd4\u81ea\u5df1\u4ece\u96f6\u5f00\u59cb\u7f16\u5199\u66f4\u6709\u6548\u7387\u3002<\/p>\n<\/p>\n<ul>\n<li>Scrapy\u662fPython\u4e2d\u6700\u53d7\u6b22\u8fce\u7684\u722c\u866b\u6846\u67b6\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u529f\u80fd\uff0c\u5982\u8bf7\u6c42\u8c03\u5ea6\u3001\u6570\u636e\u63d0\u53d6\u548c\u5b58\u50a8\u7b49\uff0c\u80fd\u591f\u5927\u5e45\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002<\/li>\n<li>\u5b66\u4e60\u5982\u4f55\u5728Scrapy\u4e2d\u5b9a\u4e49Item\u3001\u7f16\u5199Spider\u3001\u4f7f\u7528Item Pipeline\u7b49\uff0c\u5bf9\u4e8e\u6784\u5efa\u9ad8\u6548\u7684\u722c\u866b\u5e94\u7528\u81f3\u5173\u91cd\u8981\u3002<\/li>\n<\/ul>\n<p><p>\u4e94\u3001\u6570\u636e\u5b58\u50a8\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>\u5c06\u6293\u53d6\u7684\u6570\u636e\u6301\u4e45\u5316\u5b58\u50a8\u662f\u722c\u866b\u5f00\u53d1\u7684\u53e6\u4e00\u91cd\u8981\u73af\u8282\u3002<\/p>\n<\/p>\n<ul>\n<li>\u4e86\u89e3\u4e0d\u540c\u7684\u6570\u636e\u5b58\u50a8\u65b9\u5f0f\uff0c\u5982\u5b58\u50a8\u5230\u6587\u4ef6\u3001\u6570\u636e\u5e93\uff08MySQL\u3001MongoDB\u7b49\uff09\u6216\u901a\u8fc7API\u53d1\u9001\u5230\u5176\u4ed6\u5e94\u7528\u3002<\/li>\n<li>\u638c\u63e1\u5982\u4f55\u5728Python\u4e2d\u64cd\u4f5c\u8fd9\u4e9b\u5b58\u50a8\u7cfb\u7edf\uff0c\u4ee5\u53ca\u5982\u4f55\u4f18\u5316\u6570\u636e\u5b58\u50a8\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\u3002<\/li>\n<\/ul>\n<p><p>\u516d\u3001\u53cd\u722c\u866b\u7b56\u7565\u53ca\u5bf9\u7b56<\/p>\n<\/p>\n<p><p>\u722c\u866b\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u4f1a\u9047\u5230\u7f51\u7ad9\u7684\u53cd\u722c\u63aa\u65bd\uff0c\u8fd9\u8981\u6c42\u5f00\u53d1\u8005\u5fc5\u987b\u4e86\u89e3\u5e38\u89c1\u7684\u53cd\u722c\u866b\u6280\u672f\uff0c\u5e76\u4e14\u80fd\u591f\u91c7\u53d6\u6709\u6548\u7684\u5e94\u5bf9\u63aa\u65bd\u3002<\/p>\n<\/p>\n<ul>\n<li>\u8bc6\u522b\u548c\u5904\u7406\u5e38\u89c1\u7684\u53cd\u722c\u866b\u673a\u5236\uff0c\u5982\u8bf7\u6c42\u9891\u7387\u9650\u5236\u3001\u9a8c\u8bc1\u7801\u3001IP\u5c01\u9501\u7b49\u3002<\/li>\n<li>\u5b66\u4f1a\u4f7f\u7528\u4ee3\u7406\u3001\u8bbe\u7f6e\u5408\u7406\u7684\u8bf7\u6c42\u5934\u3001\u6a21\u62df\u6d4f\u89c8\u5668\u884c\u4e3a\u7b49\u7b56\u7565\uff0c\u89c4\u907f\u7f51\u7ad9\u7684\u53cd\u722c\u63aa\u65bd\u3002<\/li>\n<\/ul>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>\u4ec0\u4e48\u662fpython\u722c\u866b\uff1f<\/strong><br \/>\nPython\u722c\u866b\u662f\u57fa\u4e8ePython\u7f16\u7a0b\u8bed\u8a00\u5f00\u53d1\u7684\u4e00\u79cd\u7f51\u7edc\u6570\u636e\u83b7\u53d6\u5de5\u5177\uff0c\u901a\u8fc7\u6a21\u62df\u8bbf\u95ee\u7f51\u9875\uff0c\u4ece\u7f51\u9875\u4e2d\u63d0\u53d6\u6240\u9700\u7684\u6570\u636e\u5e76\u8fdb\u884c\u5904\u7406\u548c\u5206\u6790\u3002<\/p>\n<p><strong>\u5982\u4f55\u5b66\u4e60python\u722c\u866b\uff1f<\/strong><br \/>\n\u8981\u5b66\u4e60python\u722c\u866b\uff0c\u9996\u5148\u9700\u8981\u4e86\u89e3\u57fa\u672c\u7684Python\u8bed\u6cd5\u548c\u64cd\u4f5c\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u5b66\u4e60\u4f7f\u7528Python\u7684\u722c\u866b\u6846\u67b6\uff08\u5982BeautifulSoup\u3001Scrapy\u7b49\uff09\uff0c\u638c\u63e1\u7f51\u9875\u89e3\u6790\u3001\u7f51\u9875\u8bf7\u6c42\u3001\u6570\u636e\u63d0\u53d6\u548c\u5b58\u50a8\u7b49\u6280\u5de7\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u9605\u8bfb\u76f8\u5173\u7684\u722c\u866b\u6559\u7a0b\u548c\u5b9e\u6218\u7ecf\u9a8c\uff0c\u901a\u8fc7\u5b9e\u9645\u9879\u76ee\u7ec3\u4e60\u6765\u63d0\u9ad8\u81ea\u5df1\u7684\u722c\u866b\u6280\u80fd\u3002<\/p>\n<p><strong>\u5982\u4f55\u5e94\u5bf9\u53cd\u722c\u866b\u673a\u5236\uff1f<\/strong><br \/>\n\u5728\u722c\u53d6\u7f51\u9875\u6570\u636e\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u7f51\u7ad9\u7684\u53cd\u722c\u866b\u673a\u5236\uff0c\u5982\u9a8c\u8bc1\u7801\u3001IP\u5c01\u7981\u7b49\u3002\u8981\u5e94\u5bf9\u8fd9\u4e9b\u53cd\u722c\u866b\u673a\u5236\uff0c\u53ef\u4ee5\u91c7\u53d6\u4e00\u4e9b\u7b56\u7565\uff0c\u4f8b\u5982\u4f7f\u7528\u4ee3\u7406IP\u8fdb\u884c\u8bf7\u6c42\u3001\u8bbe\u7f6e\u8bf7\u6c42\u7684\u95f4\u9694\u65f6\u95f4\u3001\u6a21\u62df\u767b\u5f55\u3001\u6a21\u62df\u6d4f\u89c8\u5668\u884c\u4e3a\u7b49\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u4e13\u95e8\u7528\u4e8e\u7834\u89e3\u53cd\u722c\u866b\u673a\u5236\u7684\u5de5\u5177\u548c\u5e93\uff0c\u5982Selenium\u3001pyppeteer\u7b49\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u722c\u866b\u5185\u5bb9\u7684\u5408\u6cd5\u6027\u548c\u9053\u5fb7\u6027\u4e5f\u9700\u8981\u88ab\u91cd\u89c6\uff0c\u4e0d\u5f97\u8fdd\u53cd\u76f8\u5173\u6cd5\u5f8b\u89c4\u5b9a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u722c\u866b\u7684\u5fc5\u5907\u77e5\u8bc6\u4e3b\u8981\u5305\u62ecHTTP\u534f\u8bae\u7684\u57fa\u7840\u77e5\u8bc6\u3001Python\u7f16\u7a0b\u57fa\u7840\u3001\u6570\u636e\u63d0\u53d6\u4e0e\u89e3\u6790\u65b9\u6cd5\u3001\u722c\u866b\u6846\u67b6\u7684 [&hellip;]","protected":false},"author":3,"featured_media":177285,"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\/177277"}],"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=177277"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/177277\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/177285"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=177277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=177277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=177277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}