{"id":228077,"date":"2024-05-11T21:01:27","date_gmt":"2024-05-11T13:01:27","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/228077.html"},"modified":"2024-05-11T21:01:35","modified_gmt":"2024-05-11T13:01:35","slug":"python%e7%88%ac%e8%99%ab%e9%83%bd%e6%9c%89%e5%93%aa%e4%ba%9b%e7%a7%8d%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/228077.html","title":{"rendered":"python\u722c\u866b\u90fd\u6709\u54ea\u4e9b\u79cd\u7c7b"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25151158\/3fbebf2d-c0b0-487d-a456-c060a275bec4.webp\" alt=\"python\u722c\u866b\u90fd\u6709\u54ea\u4e9b\u79cd\u7c7b\" \/><\/p>\n<p><p>Python\u722c\u866b\u7684\u79cd\u7c7b\u4e3b\u8981\u5305\u62ec<strong>\u57fa\u672c\u7684\u9759\u6001\u9875\u9762\u722c\u866b\u3001\u52a8\u6001\u9875\u9762\u722c\u866b\u3001\u81ea\u52a8\u5316\u6d4b\u8bd5\u5de5\u5177\u5b9e\u73b0\u7684\u722c\u866b<\/strong>\u4ee5\u53ca<strong>\u5206\u5e03\u5f0f\u722c\u866b<\/strong>\u3002\u5176\u4e2d\uff0c<strong>\u57fa\u672c\u7684\u9759\u6001\u9875\u9762\u722c\u866b<\/strong>\u6700\u4e3a\u521d\u7ea7\u548c\u5e38\u89c1\uff0c\u5b83\u76f4\u63a5\u8bf7\u6c42\u7f51\u9875\u5e76\u83b7\u53d6HTML\u6587\u6863\uff0c\u8fdb\u800c\u89e3\u6790\u9700\u8981\u7684\u6570\u636e\u3002\u8fd9\u7c7b\u722c\u866b\u7684\u5b9e\u73b0\u901a\u5e38\u4f9d\u8d56\u4e8ePython\u7684requests\u5e93\u548cBeautifulSoup\u6216lxml\u5e93\uff0c\u9002\u7528\u4e8e\u5904\u7406\u9759\u6001\u5185\u5bb9\u7684\u7f51\u7ad9\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u57fa\u672c\u7684\u9759\u6001\u9875\u9762\u722c\u866b<\/h2>\n<\/p>\n<p><p>\u57fa\u672c\u7684\u9759\u6001\u9875\u9762\u722c\u866b\u4e3b\u8981\u901a\u8fc7HTTP\u8bf7\u6c42\u76f4\u63a5\u83b7\u53d6\u7f51\u9875\u7684HTML\u5185\u5bb9\uff0c\u9002\u7528\u4e8e\u9875\u9762\u5185\u5bb9\u5728HTML\u4ee3\u7801\u4e2d\u76f4\u63a5\u660e\u786e\u663e\u793a\u7684\u7f51\u7ad9\u3002\u8fd9\u79cd\u722c\u866b\u5b9e\u73b0\u76f8\u5bf9\u7b80\u5355\uff0c\u901a\u5e38\u4f7f\u7528Python\u7684requests\u6216urllib\u5e93\u53d1\u9001HTTP\u8bf7\u6c42\uff0c\u7136\u540e\u5229\u7528BeautifulSoup\u6216lxml\u7b49\u89e3\u6790\u5e93\u6765\u89e3\u6790HTML\u6587\u6863\uff0c\u63d0\u53d6\u51fa\u6240\u9700\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u8fd9\u7c7b\u722c\u866b\u7684\u4f18\u70b9\u662f\u5b9e\u73b0\u7b80\u5355\u3001\u6267\u884c\u6548\u7387\u9ad8\u3002\u4f46\u7531\u4e8e\u5b83\u76f4\u63a5\u83b7\u53d6\u7684\u662f\u9759\u6001HTML\u5185\u5bb9\uff0c\u5bf9\u4e8e\u4e00\u4e9b\u901a\u8fc7JavaScript\u52a8\u6001\u751f\u6210\u5185\u5bb9\u7684\u7f51\u7ad9\uff0c\u5219\u65e0\u6cd5\u76f4\u63a5\u6293\u53d6\u5230\u52a8\u6001\u52a0\u8f7d\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u52a8\u6001\u9875\u9762\u722c\u866b<\/h2>\n<\/p>\n<p><p>\u52a8\u6001\u9875\u9762\u722c\u866b\u4e3b\u8981\u5e94\u5bf9\u90a3\u4e9b\u5229\u7528Ajax\u3001WebSocket\u7b49\u6280\u672f\u52a8\u6001\u52a0\u8f7d\u5185\u5bb9\u7684\u7f51\u7ad9\u3002\u8fd9\u7c7b\u722c\u866b\u9700\u8981\u80fd\u591f\u6267\u884cJavaScript\u4ee3\u7801\uff0c\u4ee5\u4fbf\u4e0e\u7f51\u7ad9\u7684\u52a8\u6001\u5185\u5bb9\u4ea4\u4e92\u5e76\u6293\u53d6\u6570\u636e\u3002\u52a8\u6001\u9875\u9762\u722c\u866b\u7684\u5b9e\u73b0\u4e00\u822c\u4f9d\u8d56\u4e8eSelenium\u3001Puppeteer\u7b49\u81ea\u52a8\u5316\u6d4b\u8bd5\u5de5\u5177\uff0c\u8fd9\u4e9b\u5de5\u5177\u80fd\u591f\u542f\u52a8\u4e00\u4e2a\u6d4f\u89c8\u5668\u5b9e\u4f8b\uff0c\u6a21\u62df\u7528\u6237\u7684\u5b9e\u9645\u8bbf\u95ee\u8fc7\u7a0b\uff0c\u83b7\u53d6\u52a8\u6001\u52a0\u8f7d\u7684\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><p>\u52a8\u6001\u9875\u9762\u722c\u866b\u89e3\u51b3\u4e86\u4f20\u7edf\u9759\u6001\u722c\u866b\u65e0\u6cd5\u5904\u7406JavaScript\u52a8\u6001\u5185\u5bb9\u7684\u95ee\u9898\uff0c\u80fd\u591f\u66f4\u51c6\u786e\u5730\u6293\u53d6\u5230\u7f51\u9875\u7684\u6700\u7ec8\u5c55\u793a\u6570\u636e\u3002\u4f46\u76f8\u5bf9\u5730\uff0c\u52a8\u6001\u9875\u9762\u722c\u866b\u5728\u5b9e\u73b0\u4e0a\u66f4\u4e3a\u590d\u6742\uff0c\u8fd0\u884c\u6548\u7387\u4e5f\u4f4e\u4e8e\u9759\u6001\u9875\u9762\u722c\u866b\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u81ea\u52a8\u5316\u6d4b\u8bd5\u5de5\u5177\u5b9e\u73b0\u7684\u722c\u866b<\/h2>\n<\/p>\n<p><p>\u81ea\u52a8\u5316\u6d4b\u8bd5\u5de5\u5177\u5b9e\u73b0\u7684\u722c\u866b\u901a\u5e38\u7528\u4e8e\u5904\u7406\u590d\u6742\u7684\u7f51\u9875\u4ea4\u4e92\uff0c\u5982\u767b\u5f55\u3001\u586b\u8868\u3001\u7ffb\u9875\u7b49\u64cd\u4f5c\u3002Selenium\u662f\u8fd9\u7c7b\u5de5\u5177\u4e2d\u6700\u5e38\u7528\u7684\u4e00\u4e2a\uff0c\u5b83\u652f\u6301\u591a\u79cd\u6d4f\u89c8\u5668\uff0c\u53ef\u4ee5\u6a21\u62df\u771f\u5b9e\u7528\u6237\u7684\u884c\u4e3a\u3002\u901a\u8fc7Selenium\uff0c\u722c\u866b\u53ef\u4ee5\u6267\u884cJavaScript\uff0c\u7b49\u5f85\u9875\u9762\u7684\u52a8\u6001\u5185\u5bb9\u52a0\u8f7d\u5b8c\u6bd5\u540e\u518d\u8fdb\u884c\u6570\u636e\u7684\u63d0\u53d6\u3002<\/p>\n<\/p>\n<p><p>\u5c3d\u7ba1\u81ea\u52a8\u5316\u6d4b\u8bd5\u5de5\u5177\u5b9e\u73b0\u7684\u722c\u866b\u975e\u5e38\u5f3a\u5927\uff0c\u4f46\u5176\u8fd0\u884c\u6548\u7387\u76f8\u5bf9\u8f83\u4f4e\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u5927\u91cf\u9875\u9762\u65f6\u3002\u6b64\u5916\uff0c\u8fd9\u7c7b\u722c\u866b\u7684\u7ef4\u62a4\u6210\u672c\u8f83\u9ad8\uff0c\u56e0\u4e3a\u5b83\u4f9d\u8d56\u4e8e\u6d4f\u89c8\u5668\u73af\u5883\uff0c\u9700\u8981\u5b9a\u671f\u66f4\u65b0\u6d4f\u89c8\u5668\u548c\u76f8\u5e94\u7684\u9a71\u52a8\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u5206\u5e03\u5f0f\u722c\u866b<\/h2>\n<\/p>\n<p><p>\u5206\u5e03\u5f0f\u722c\u866b\u662f\u6307\u901a\u8fc7\u591a\u4e2a\u722c\u866b\u5b9e\u4f8b\u534f\u540c\u5de5\u4f5c\uff0c\u5171\u540c\u5b8c\u6210\u6570\u636e\u6293\u53d6\u4efb\u52a1\u7684\u722c\u866b\u3002\u8fd9\u4e9b\u722c\u866b\u5b9e\u4f8b\u53ef\u4ee5\u5206\u5e03\u5728\u4e0d\u540c\u7684\u670d\u52a1\u5668\u6216\u8fdb\u7a0b\u4e2d\uff0c\u901a\u8fc7\u7f51\u7edc\u6216\u5176\u4ed6\u65b9\u5f0f\u8fdb\u884c\u901a\u4fe1\u534f\u8c03\u3002\u5206\u5e03\u5f0f\u722c\u866b\u901a\u5e38\u9002\u7528\u4e8e\u5927\u89c4\u6a21\u6570\u636e\u6293\u53d6\u4efb\u52a1\uff0c\u80fd\u591f\u5927\u5927\u63d0\u9ad8\u722c\u53d6\u6548\u7387\u548c\u6570\u636e\u5904\u7406\u80fd\u529b\u3002<\/p>\n<\/p>\n<p><p>Scrapy\u662f\u652f\u6301\u5206\u5e03\u5f0f\u722c\u53d6\u7684Python\u6846\u67b6\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6293\u53d6\u3001\u5904\u7406\u548c\u5b58\u50a8\u529f\u80fd\uff0c\u975e\u5e38\u9002\u5408\u5f00\u53d1\u590d\u6742\u7684\u722c\u866b\u9879\u76ee\u3002\u901a\u8fc7\u7ed3\u5408Scrapy-Redis\u7b49\u7ec4\u4ef6\uff0cScrapy\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u5206\u5e03\u5f0f\u722c\u53d6\u3002<\/p>\n<\/p>\n<p><p>\u5206\u5e03\u5f0f\u722c\u866b\u7684\u6311\u6218\u5728\u4e8e\u722c\u866b\u7684\u7ba1\u7406\u548c\u534f\u8c03\uff0c\u5982\u4f55\u9ad8\u6548\u5730\u5206\u914d\u4efb\u52a1\u3001\u5904\u7406\u722c\u866b\u95f4\u7684\u901a\u4fe1\u4ee5\u53ca\u6570\u636e\u7684\u5408\u5e76\u7b49\u95ee\u9898\u3002\u4f46\u5f97\u76ca\u4e8e\u73b0\u6709\u6210\u719f\u7684\u6846\u67b6\u548c\u5de5\u5177\uff0c\u5f00\u53d1\u9ad8\u6548\u7684\u5206\u5e03\u5f0f\u722c\u866b\u5df2\u7ecf\u53d8\u5f97\u66f4\u52a0\u53ef\u884c\u3002<\/p>\n<\/p>\n<p><p>Python\u722c\u866b\u7684\u79cd\u7c7b\u7e41\u591a\uff0c\u4ece\u5904\u7406\u7b80\u5355\u7684\u9759\u6001\u7f51\u9875\u5230\u590d\u6742\u7684\u52a8\u6001\u5185\u5bb9\uff0c\u518d\u5230\u5927\u89c4\u6a21\u7684\u5206\u5e03\u5f0f\u722c\u53d6\uff0c\u4e0d\u540c\u7684\u5e94\u7528\u573a\u666f\u548c\u9700\u6c42\u51b3\u5b9a\u4e86\u722c\u866b\u6280\u672f\u7684\u9009\u62e9\u3002\u5bf9\u4e8e\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u4e86\u89e3\u5404\u7c7b\u722c\u866b\u7684\u7279\u70b9\u548c\u9002\u7528\u8303\u56f4\uff0c\u80fd\u591f\u66f4\u6709\u6548\u5730\u89e3\u51b3\u5b9e\u9645\u7684\u6570\u636e\u6293\u53d6\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u4ec0\u4e48\u662fPython\u722c\u866b\uff1f<\/strong><br \/>\nPython\u722c\u866b\u662f\u6307\u4f7f\u7528Python\u811a\u672c\u7f16\u5199\u7684\u7a0b\u5e8f\uff0c\u7528\u4e8e\u81ea\u52a8\u83b7\u53d6\u4e92\u8054\u7f51\u4e0a\u7684\u6570\u636e\u4fe1\u606f\u3002\u901a\u8fc7\u6a21\u62df\u7528\u6237\u8bf7\u6c42\u548c\u89e3\u6790\u7f51\u9875\u5185\u5bb9\uff0c\u722c\u866b\u53ef\u4ee5\u4ece\u7f51\u9875\u4e2d\u63d0\u53d6\u6240\u9700\u7684\u6570\u636e\uff0c\u5e76\u4fdd\u5b58\u6216\u5904\u7406\u8fd9\u4e9b\u6570\u636e\u3002<\/p>\n<p><strong>2. \u5e38\u89c1\u7684Python\u722c\u866b\u79cd\u7c7b\u6709\u54ea\u4e9b\uff1f<\/strong><\/p>\n<ul>\n<li>\u901a\u7528\u722c\u866b\uff1a\u901a\u7528\u722c\u866b\u662f\u4e00\u79cd\u80fd\u591f\u722c\u53d6\u5e7f\u6cdb\u7f51\u9875\u7684\u722c\u866b\uff0c\u901a\u8fc7\u6293\u53d6\u641c\u7d22\u5f15\u64ce\u7d22\u5f15\u7684\u7f51\u9875\uff0c\u6765\u83b7\u53d6\u5927\u91cf\u7684\u6570\u636e\u4fe1\u606f\u3002\u5e38\u7528\u7684\u901a\u7528\u722c\u866b\u5de5\u5177\u6709Scrapy\u3001Beautiful Soup\u7b49\u3002<\/li>\n<li>\u975e\u7ed3\u6784\u5316\u6570\u636e\u722c\u866b\uff1a\u975e\u7ed3\u6784\u5316\u6570\u636e\u722c\u866b\u4e3b\u8981\u7528\u4e8e\u722c\u53d6\u975e\u89c4\u5219\u5316\u7684\u6570\u636e\u4fe1\u606f\uff0c\u5982\u793e\u4ea4\u5a92\u4f53\u4e0a\u7684\u52a8\u6001\u6570\u636e\u3001\u65b0\u95fb\u62a5\u9053\u7b49\u3002\u8fd9\u7c7b\u722c\u866b\u9700\u8981\u5177\u5907\u4e00\u5b9a\u7684\u667a\u80fd\u5206\u6790\u548c\u5904\u7406\u80fd\u529b\uff0c\u4ee5\u5e94\u5bf9\u4e0d\u540c\u7684\u6570\u636e\u683c\u5f0f\u548c\u5185\u5bb9\u3002\u5e38\u7528\u7684\u975e\u7ed3\u6784\u5316\u6570\u636e\u722c\u866b\u5de5\u5177\u6709Python\u7684Selenium\u3001PhantomJS\u7b49\u3002<\/li>\n<li>\u6570\u636e\u6316\u6398\u722c\u866b\uff1a\u6570\u636e\u6316\u6398\u722c\u866b\u4e3b\u8981\u7528\u4e8e\u901a\u8fc7\u5927\u89c4\u6a21\u6570\u636e\u7684\u722c\u53d6\u548c\u5904\u7406\uff0c\u6765\u6316\u6398\u548c\u53d1\u73b0\u9690\u85cf\u5728\u6570\u636e\u80cc\u540e\u7684\u4fe1\u606f\u3002\u8fd9\u79cd\u722c\u866b\u5e38\u7528\u4e8e\u4f01\u4e1a\u7684\u5e02\u573a\u8c03\u7814\u3001\u7ade\u4e89\u60c5\u62a5\u6536\u96c6\u7b49\u9886\u57df\u3002\u5e38\u7528\u7684\u6570\u636e\u6316\u6398\u722c\u866b\u5de5\u5177\u6709Python\u7684Scrapy\u3001Beautiful Soup\u7b49\u3002<\/li>\n<li>\u805a\u7126\u722c\u866b\uff1a\u805a\u7126\u722c\u866b\u662f\u4e00\u79cd\u9488\u5bf9\u7279\u5b9a\u9886\u57df\u6216\u7279\u5b9a\u7f51\u7ad9\u7684\u722c\u866b\uff0c\u5b83\u901a\u8fc7\u8bbe\u7f6e\u7279\u5b9a\u7684\u89c4\u5219\u548c\u8fc7\u6ee4\u6761\u4ef6\uff0c\u53ea\u83b7\u53d6\u6240\u9700\u7684\u6570\u636e\u4fe1\u606f\u3002\u8fd9\u79cd\u722c\u866b\u53ef\u4ee5\u6709\u6548\u5730\u63d0\u9ad8\u6570\u636e\u83b7\u53d6\u7684\u6548\u7387\u548c\u51c6\u786e\u6027\u3002\u5e38\u7528\u7684\u805a\u7126\u722c\u866b\u5de5\u5177\u6709Python\u7684Scrapy\u3001Beautiful Soup\u7b49\u3002<\/li>\n<\/ul>\n<p><strong>3. \u5982\u4f55\u9009\u62e9\u5408\u9002\u7684Python\u722c\u866b\u79cd\u7c7b\uff1f<\/strong><br \/>\n\u9009\u62e9\u5408\u9002\u7684Python\u722c\u866b\u79cd\u7c7b\u8981\u6839\u636e\u5177\u4f53\u7684\u9700\u6c42\u548c\u9879\u76ee\u8981\u6c42\u6765\u8fdb\u884c\u8bc4\u4f30\u3002\u5982\u679c\u9700\u8981\u722c\u53d6\u5927\u91cf\u7684\u7f51\u9875\u6570\u636e\u5e76\u6784\u5efa\u641c\u7d22\u5f15\u64ce\uff0c\u53ef\u4ee5\u9009\u62e9\u901a\u7528\u722c\u866b\uff1b\u5982\u679c\u9700\u8981\u722c\u53d6\u975e\u89c4\u5219\u5316\u7684\u6570\u636e\u4fe1\u606f\uff0c\u53ef\u4ee5\u9009\u62e9\u975e\u7ed3\u6784\u5316\u6570\u636e\u722c\u866b\uff1b\u5982\u679c\u9700\u8981\u901a\u8fc7\u6570\u636e\u6316\u6398\u6765\u53d1\u73b0\u9690\u85cf\u4fe1\u606f\uff0c\u53ef\u4ee5\u9009\u62e9\u6570\u636e\u6316\u6398\u722c\u866b\uff1b\u5982\u679c\u9700\u8981\u805a\u7126\u722c\u53d6\u7279\u5b9a\u9886\u57df\u6216\u7279\u5b9a\u7f51\u7ad9\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u9009\u62e9\u805a\u7126\u722c\u866b\u3002\u540c\u65f6\uff0c\u8fd8\u9700\u8981\u8003\u8651\u81ea\u5df1\u7684\u6280\u672f\u6c34\u5e73\u548c\u9879\u76ee\u8d44\u6e90\uff0c\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u548c\u6846\u67b6\u6765\u8fdb\u884c\u5f00\u53d1\u548c\u5b9e\u65bd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u722c\u866b\u7684\u79cd\u7c7b\u4e3b\u8981\u5305\u62ec\u57fa\u672c\u7684\u9759\u6001\u9875\u9762\u722c\u866b\u3001\u52a8\u6001\u9875\u9762\u722c\u866b\u3001\u81ea\u52a8\u5316\u6d4b\u8bd5\u5de5\u5177\u5b9e\u73b0\u7684\u722c\u866b\u4ee5\u53ca\u5206\u5e03\u5f0f\u722c\u866b\u3002\u5176\u4e2d\uff0c [&hellip;]","protected":false},"author":3,"featured_media":228086,"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\/228077"}],"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=228077"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/228077\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/228086"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=228077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=228077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=228077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}