{"id":12802,"date":"2025-04-18T19:55:24","date_gmt":"2025-04-18T11:55:24","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/12802.html"},"modified":"2025-04-18T19:55:24","modified_gmt":"2025-04-18T11:55:24","slug":"python%e7%88%ac%e8%99%ab%ef%bc%9a%e5%bc%80%e5%90%af%e6%95%b0%e6%8d%ae%e6%8a%93%e5%8f%96%e7%9a%84%e5%a5%87%e5%b9%bb%e4%b9%8b%e6%97%85%ef%bc%88%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/12802.html","title":{"rendered":"Python\u722c\u866b\uff1a\u5f00\u542f\u6570\u636e\u6293\u53d6\u7684\u5947\u5e7b\u4e4b\u65c5\uff08\u4e00\uff09"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E4%B8%80%E3%80%81%E7%88%AC%E8%99%AB%E5%88%9D%E5%8D%B0%E8%B1%A1%EF%BC%9A%E6%8F%AD%E5%BC%80%E7%A5%9E%E7%A7%98%E9%9D%A2%E7%BA%B1%E2%80%8B-toc\" style=\"margin-left:0px\">\u4e00\u3001\u722c\u866b\u521d\u5370\u8c61&#xff1a;\u63ed\u5f00\u795e\u79d8\u9762\u7eb1\u200b<\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E5%B7%A5%E6%AC%B2%E5%96%84%E5%85%B6%E4%BA%8B%EF%BC%9A%E5%89%8D%E6%9C%9F%E5%87%86%E5%A4%87%E2%80%8B-toc\" style=\"margin-left:0px\">\u4e8c\u3001\u5de5\u6b32\u5584\u5176\u4e8b&#xff1a;\u524d\u671f\u51c6\u5907\u200b<\/p>\n<p id=\"%EF%BC%88%E4%B8%80%EF%BC%89Python%20%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA%E2%80%8B-toc\" style=\"margin-left:40px\">&#xff08;\u4e00&#xff09;Python \u73af\u5883\u642d\u5efa\u200b<\/p>\n<p id=\"1.%E4%B8%8B%E8%BD%BD%20Python%20%E5%AE%89%E8%A3%85%E5%8C%85%EF%BC%9A%E2%80%8B-toc\" style=\"margin-left:80px\">1.\u4e0b\u8f7d Python \u5b89\u88c5\u5305&#xff1a;\u200b<\/p>\n<p id=\"2.%E8%BF%90%E8%A1%8C%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F%EF%BC%9A%E2%80%8B-toc\" style=\"margin-left:80px\">2.\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f&#xff1a;\u200b<\/p>\n<p id=\"3.%E9%85%8D%E7%BD%AE%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%EF%BC%88%E8%8B%A5%E8%87%AA%E5%8A%A8%E6%B7%BB%E5%8A%A0%E5%A4%B1%E8%B4%A5%EF%BC%89%EF%BC%9A%E2%80%8B-toc\" style=\"margin-left:80px\">3.\u914d\u7f6e\u73af\u5883\u53d8\u91cf&#xff08;\u82e5\u81ea\u52a8\u6dfb\u52a0\u5931\u8d25&#xff09;&#xff1a;\u200b<\/p>\n<p id=\"%EF%BC%88%E4%BA%8C%EF%BC%89%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7%E6%8E%A8%E8%8D%90%E2%80%8B-toc\" style=\"margin-left:40px\">&#xff08;\u4e8c&#xff09;\u5f00\u53d1\u5de5\u5177\u63a8\u8350\u200b<\/p>\n<p id=\"1.PyCharm%EF%BC%9A%E2%80%8B-toc\" style=\"margin-left:80px\">1.PyCharm&#xff1a;\u200b<\/p>\n<p id=\"2.Jupyter%20Notebook%EF%BC%9A%E2%80%8B-toc\" style=\"margin-left:80px\">2.Jupyter Notebook&#xff1a;\u200b<\/p>\n<p id=\"%EF%BC%88%E4%B8%89%EF%BC%89%E5%BF%85%E5%A4%87%E5%BA%93%E5%AE%89%E8%A3%85%E2%80%8B-toc\" style=\"margin-left:40px\">&#xff08;\u4e09&#xff09;\u5fc5\u5907\u5e93\u5b89\u88c5\u200b<\/p>\n<p id=\"1.requests%20%E5%BA%93%EF%BC%9A%E2%80%8B-toc\" style=\"margin-left:80px\">1.requests \u5e93&#xff1a;\u200b<\/p>\n<p id=\"2.BeautifulSoup4%20%E5%BA%93%EF%BC%9A%E2%80%8B-toc\" style=\"margin-left:80px\">2.BeautifulSoup4 \u5e93&#xff1a;\u200b<\/p>\n<p id=\"3.Scrapy%20%E6%A1%86%E6%9E%B6%EF%BC%9A%E2%80%8B-toc\" style=\"margin-left:80px\">3.Scrapy \u6846\u67b6&#xff1a;\u200b<\/p>\n<p id=\"4.Selenium%20%E5%BA%93%EF%BC%9A%E2%80%8B-toc\" style=\"margin-left:80px\">4.Selenium \u5e93&#xff1a;\u200b<\/p>\n<p id=\"%E4%B8%89%E3%80%81%E7%88%AC%E8%99%AB%E5%8E%9F%E7%90%86%E5%89%96%E6%9E%90%EF%BC%9A%E6%8E%A2%E5%AF%BB%E5%86%85%E5%9C%A8%E6%9C%BA%E5%88%B6%E2%80%8B-toc\" style=\"margin-left:0px\">\u4e09\u3001\u722c\u866b\u539f\u7406\u5256\u6790&#xff1a;\u63a2\u5bfb\u5185\u5728\u673a\u5236\u200b<\/p>\n<p id=\"%EF%BC%88%E4%B8%80%EF%BC%89%E5%8F%91%E8%B5%B7%E8%AF%B7%E6%B1%82%E2%80%8B-toc\" style=\"margin-left:40px\">&#xff08;\u4e00&#xff09;\u53d1\u8d77\u8bf7\u6c42\u200b<\/p>\n<p id=\"%EF%BC%88%E4%BA%8C%EF%BC%89%E8%8E%B7%E5%8F%96%E5%93%8D%E5%BA%94%E2%80%8B-toc\" style=\"margin-left:40px\">&#xff08;\u4e8c&#xff09;\u83b7\u53d6\u54cd\u5e94\u200b<\/p>\n<p id=\"%EF%BC%88%E4%B8%89%EF%BC%89%E8%A7%A3%E6%9E%90%E5%86%85%E5%AE%B9%E2%80%8B-toc\" style=\"margin-left:40px\">&#xff08;\u4e09&#xff09;\u89e3\u6790\u5185\u5bb9\u200b<\/p>\n<p id=\"%EF%BC%88%E5%9B%9B%EF%BC%89%E4%BF%9D%E5%AD%98%E6%95%B0%E6%8D%AE%E2%80%8B-toc\" style=\"margin-left:40px\">&#xff08;\u56db&#xff09;\u4fdd\u5b58\u6570\u636e\u200b<\/p>\n<hr id=\"hr-toc\" \/>\n<p>\u00a0<\/p>\n<h2 id=\"%E4%B8%80%E3%80%81%E7%88%AC%E8%99%AB%E5%88%9D%E5%8D%B0%E8%B1%A1%EF%BC%9A%E6%8F%AD%E5%BC%80%E7%A5%9E%E7%A7%98%E9%9D%A2%E7%BA%B1%E2%80%8B\">\u4e00\u3001\u722c\u866b\u521d\u5370\u8c61&#xff1a;\u63ed\u5f00\u795e\u79d8\u9762\u7eb1\u200b<\/h2>\n<p>\u5728\u4e92\u8054\u7f51\u8fd9\u4e2a\u5e7f\u88a4\u65e0\u57a0\u7684\u4fe1\u606f\u5b87\u5b99\u4e2d&#xff0c;\u6570\u636e\u5982\u540c\u7e41\u661f\u822c\u7480\u74a8\u7e41\u591a\u3002\u800c Python \u7f51\u7edc\u722c\u866b&#xff0c;\u5c31\u50cf\u662f\u4e00\u4f4d\u795e\u79d8\u800c\u5f3a\u5927\u7684 \u201c\u6570\u636e\u63a2\u9669\u5bb6\u201d&#xff0c;\u80fd\u591f\u6309\u7167\u65e2\u5b9a\u89c4\u5219&#xff0c;\u81ea\u52a8\u7a7f\u68ad\u4e8e\u7f51\u7edc\u4e16\u754c&#xff0c;\u6293\u53d6\u6211\u4eec\u6240\u9700\u7684\u6570\u636e\u3002\u200b<\/p>\n<p>\u4ece\u5b9a\u4e49\u4e0a\u6765\u8bf4&#xff0c;\u7f51\u7edc\u722c\u866b\u662f\u4e00\u79cd\u81ea\u52a8\u5316\u7a0b\u5e8f&#xff0c;\u5b83\u6a21\u4eff\u4eba\u7c7b\u5728\u6d4f\u89c8\u5668\u4e2d\u7684\u64cd\u4f5c\u884c\u4e3a&#xff0c;\u5411\u7f51\u9875\u670d\u52a1\u5668\u53d1\u9001\u8bf7\u6c42&#xff0c;\u83b7\u53d6\u7f51\u9875\u5185\u5bb9&#xff0c;\u5e76\u5bf9\u8fd9\u4e9b\u5185\u5bb9\u8fdb\u884c\u89e3\u6790\u548c\u63d0\u53d6&#xff0c;\u4ece\u800c\u83b7\u53d6\u6709\u4ef7\u503c\u7684\u6570\u636e\u3002\u4f60\u53ef\u4ee5\u628a\u5b83\u60f3\u8c61\u6210\u4e00\u4e2a\u52e4\u52b3\u7684\u5c0f\u871c\u8702&#xff0c;\u5728\u4e07\u7ef4\u7f51\u8fd9\u4e2a\u5927\u82b1\u56ed\u91cc&#xff0c;\u4e0d\u77e5\u75b2\u5026\u5730\u91c7\u96c6\u7740 \u201c\u6570\u636e\u82b1\u871c\u201d\u3002\u200b<\/p>\n<p>Python \u4f5c\u4e3a\u5f53\u4e0b\u6700\u70ed\u95e8\u7684\u7f16\u7a0b\u8bed\u8a00\u4e4b\u4e00&#xff0c;\u5728\u722c\u866b\u9886\u57df\u6709\u7740\u65e0\u53ef\u6bd4\u62df\u7684\u4f18\u52bf\u3002\u9996\u5148&#xff0c;Python \u7684\u8bed\u6cd5\u7b80\u6d01\u660e\u4e86&#xff0c;\u5c31\u50cf\u4e00\u672c\u901a\u4fd7\u6613\u61c2\u7684\u6545\u4e8b\u4e66&#xff0c;\u5373\u4f7f\u662f\u7f16\u7a0b\u5c0f\u767d\u4e5f\u80fd\u8f7b\u677e\u4e0a\u624b\u3002\u76f8\u6bd4\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00&#xff0c;Python \u4ee3\u7801\u91cf\u66f4\u5c11&#xff0c;\u7ed3\u6784\u66f4\u52a0\u6e05\u6670&#xff0c;\u8fd9\u4f7f\u5f97\u5f00\u53d1\u8005\u80fd\u591f\u66f4\u5feb\u901f\u5730\u7f16\u5199\u548c\u8c03\u8bd5\u722c\u866b\u7a0b\u5e8f&#xff0c;\u5927\u5927\u63d0\u9ad8\u4e86\u5f00\u53d1\u6548\u7387\u3002\u4f8b\u5982&#xff0c;\u5728 Python \u4e2d&#xff0c;\u4f7f\u7528requests\u5e93\u53d1\u9001\u4e00\u4e2a HTTP \u8bf7\u6c42\u53ea\u9700\u8981\u77ed\u77ed\u4e00\u884c\u4ee3\u7801&#xff1a;response &#061; requests.get(url)&#xff0c;\u7b80\u6d01\u9ad8\u6548&#xff0c;\u4e00\u76ee\u4e86\u7136\u3002\u200b<\/p>\n<p>\u5176\u6b21&#xff0c;Python \u62e5\u6709\u4e30\u5bcc\u7684\u722c\u866b\u5e93\u548c\u6846\u67b6&#xff0c;\u8fd9\u4e9b\u5f3a\u5927\u7684\u5de5\u5177\u5c31\u50cf\u662f\u7ed9\u722c\u866b\u914d\u5907\u4e86\u5404\u79cd\u795e\u5947\u7684\u88c5\u5907&#xff0c;\u8ba9\u5b83\u5728\u6570\u636e\u6293\u53d6\u7684\u9053\u8def\u4e0a\u5982\u864e\u6dfb\u7ffc\u3002\u6bd4\u5982BeautifulSoup\u5e93&#xff0c;\u5b83\u53ef\u4ee5\u8f7b\u677e\u5730\u89e3\u6790 HTML \u548c XML \u6587\u6863&#xff0c;\u63d0\u53d6\u51fa\u6211\u4eec\u9700\u8981\u7684\u6570\u636e&#xff0c;\u5c31\u50cf\u4e00\u628a\u7cbe\u51c6\u7684\u624b\u672f\u5200&#xff0c;\u80fd\u591f\u5728\u590d\u6742\u7684\u7f51\u9875\u7ed3\u6784\u4e2d\u51c6\u786e\u5730 \u201c\u5207\u5272\u201d \u51fa\u6240\u9700\u4fe1\u606f&#xff1b;Scrapy\u6846\u67b6\u5219\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7ea7\u7684\u529f\u80fd&#xff0c;\u5982\u5206\u5e03\u5f0f\u722c\u53d6\u3001\u81ea\u52a8\u5904\u7406\u8bf7\u6c42\u961f\u5217\u3001\u4e2d\u95f4\u4ef6\u673a\u5236\u7b49&#xff0c;\u4f7f\u5f97\u6211\u4eec\u53ef\u4ee5\u6784\u5efa\u5927\u89c4\u6a21\u3001\u9ad8\u6027\u80fd\u7684\u722c\u866b\u7cfb\u7edf\u3002\u200b<\/p>\n<p>\u6b64\u5916&#xff0c;Python \u8fd8\u5177\u5907\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u80fd\u529b&#xff0c;\u8fd9\u5bf9\u4e8e\u722c\u866b\u83b7\u53d6\u5230\u7684\u6570\u636e\u540e\u7eed\u5904\u7406\u975e\u5e38\u5173\u952e\u3002\u501f\u52a9Pandas\u548cNumPy\u7b49\u5e93&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5bf9\u722c\u53d6\u5230\u7684\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u3001\u7b5b\u9009\u3001\u805a\u5408\u548c\u53ef\u89c6\u5316\u7b49\u64cd\u4f5c&#xff0c;\u5c06\u539f\u59cb\u6570\u636e\u8f6c\u5316\u4e3a\u6709\u4ef7\u503c\u7684\u4fe1\u606f&#xff0c;\u4e3a\u6570\u636e\u5206\u6790\u548c\u51b3\u7b56\u63d0\u4f9b\u6709\u529b\u652f\u6301\u3002\u800c\u4e14&#xff0c;Python \u62e5\u6709\u5e9e\u5927\u7684\u5f00\u53d1\u8005\u793e\u533a\u548c\u4e30\u5bcc\u7684\u8d44\u6e90&#xff0c;\u5f53\u6211\u4eec\u5728\u5f00\u53d1\u722c\u866b\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898\u65f6&#xff0c;\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u5728\u793e\u533a\u4e2d\u5bfb\u6c42\u5e2e\u52a9&#xff0c;\u501f\u9274\u5176\u4ed6\u5f00\u53d1\u8005\u7684\u7ecf\u9a8c\u548c\u89e3\u51b3\u65b9\u6848\u3002\u200b<\/p>\n<h2 id=\"%E4%BA%8C%E3%80%81%E5%B7%A5%E6%AC%B2%E5%96%84%E5%85%B6%E4%BA%8B%EF%BC%9A%E5%89%8D%E6%9C%9F%E5%87%86%E5%A4%87%E2%80%8B\">\u4e8c\u3001\u5de5\u6b32\u5584\u5176\u4e8b&#xff1a;\u524d\u671f\u51c6\u5907\u200b<\/h2>\n<h3 id=\"%EF%BC%88%E4%B8%80%EF%BC%89Python%20%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA%E2%80%8B\">&#xff08;\u4e00&#xff09;Python \u73af\u5883\u642d\u5efa\u200b<\/h3>\n<p>\u5728\u6b63\u5f0f\u5f00\u542f Python \u7f51\u7edc\u722c\u866b\u4e4b\u65c5\u524d&#xff0c;\u6211\u4eec\u9996\u5148\u5f97\u642d\u5efa\u597d Python \u8fd0\u884c\u73af\u5883&#xff0c;\u8fd9\u5c31\u597d\u6bd4\u4e3a\u722c\u866b\u6253\u9020\u4e00\u4e2a\u575a\u56fa\u7684 \u201c\u6218\u8f66\u201d\u3002\u200b<\/p>\n<h4 id=\"1.%E4%B8%8B%E8%BD%BD%20Python%20%E5%AE%89%E8%A3%85%E5%8C%85%EF%BC%9A%E2%80%8B\">1.\u4e0b\u8f7d Python \u5b89\u88c5\u5305&#xff1a;\u200b<\/h4>\n<p>\u6253\u5f00\u6d4f\u89c8\u5668&#xff0c;\u8bbf\u95ee Python \u5b98\u65b9\u7f51\u7ad9&#xff08;https:\/\/www.python.org\/downloads\/ &#xff09;\u3002\u5728\u4e0b\u8f7d\u9875\u9762&#xff0c;\u4f60\u4f1a\u770b\u5230\u4e0d\u540c\u7248\u672c\u7684 Python \u53ef\u4f9b\u9009\u62e9\u3002\u5f3a\u70c8\u63a8\u8350\u4e0b\u8f7d\u6700\u65b0\u7684\u7a33\u5b9a\u7248\u672c&#xff0c;\u56e0\u4e3a\u65b0\u7248\u672c\u901a\u5e38\u4f1a\u4fee\u590d\u4e00\u4e9b\u65e7\u7248\u672c\u7684\u6f0f\u6d1e&#xff0c;\u5e76\u4e14\u589e\u52a0\u4e86\u65b0\u7684\u529f\u80fd\u3002\u5982\u679c\u4f60\u4e0d\u786e\u5b9a\u9009\u62e9\u54ea\u4e2a\u7248\u672c&#xff0c;\u4e00\u822c\u6765\u8bf4&#xff0c;\u9009\u62e9\u5e26\u6709 \u201cPython 3.x\u201d \u5b57\u6837\u7684\u7248\u672c\u5373\u53ef&#xff0c;\u76ee\u524d Python 3.10 \u53ca\u4ee5\u4e0a\u7248\u672c\u90fd\u662f\u4e0d\u9519\u7684\u9009\u62e9 \u3002\u6839\u636e\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf&#xff08;Windows\u3001Mac OS \u6216 Linux&#xff09;&#xff0c;\u70b9\u51fb\u76f8\u5e94\u7684\u4e0b\u8f7d\u94fe\u63a5\u3002\u4f8b\u5982&#xff0c;\u5728 Windows \u7cfb\u7edf\u4e0b&#xff0c;\u4f60\u53ef\u4ee5\u9009\u62e9 \u201cWindows installer (64-bit)\u201d \u4e0b\u8f7d 64 \u4f4d\u7684\u5b89\u88c5\u5305&#xff0c;\u5982\u679c\u4f60\u7684\u7535\u8111\u662f 32 \u4f4d\u7cfb\u7edf&#xff0c;\u5219\u9009\u62e9 \u201cWindows installer (32-bit)\u201d \u3002\u200b<\/p>\n<h4 id=\"2.%E8%BF%90%E8%A1%8C%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F%EF%BC%9A%E2%80%8B\">2.\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f&#xff1a;\u200b<\/h4>\n<p>\u4e0b\u8f7d\u5b8c\u6210\u540e&#xff0c;\u627e\u5230\u4e0b\u8f7d\u7684\u5b89\u88c5\u5305&#xff0c;\u901a\u5e38\u662f\u4e00\u4e2a\u4ee5.exe\u7ed3\u5c3e\u7684\u6587\u4ef6&#xff0c;\u53cc\u51fb\u8fd0\u884c\u5b83\u3002\u5728\u5b89\u88c5\u5411\u5bfc\u754c\u9762&#xff0c;\u4f60\u4f1a\u770b\u5230\u4e00\u4e9b\u9009\u9879&#xff0c;\u52a1\u5fc5\u52fe\u9009 \u201cAdd Python 3.x to PATH\u201d \u9009\u9879&#xff0c;\u8fd9\u4e00\u6b65\u81f3\u5173\u91cd\u8981&#xff0c;\u5b83\u4f1a\u81ea\u52a8\u5c06 Python \u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d&#xff0c;\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u4f7f\u7528 Python \u547d\u4ee4\u4e86\u3002\u7136\u540e\u70b9\u51fb \u201cInstall Now\u201d \u8fdb\u884c\u9ed8\u8ba4\u5b89\u88c5&#xff0c;\u5982\u679c\u4f60\u60f3\u81ea\u5b9a\u4e49\u5b89\u88c5\u8def\u5f84&#xff0c;\u4e5f\u53ef\u4ee5\u9009\u62e9 \u201cCustomize installation\u201d \u6765\u81ea\u884c\u6307\u5b9a\u5b89\u88c5\u4f4d\u7f6e\u3002\u5b89\u88c5\u8fc7\u7a0b\u53ef\u80fd\u9700\u8981\u4e00\u4e9b\u65f6\u95f4&#xff0c;\u8bf7\u8010\u5fc3\u7b49\u5f85\u3002\u200b<\/p>\n<h4 id=\"3.%E9%85%8D%E7%BD%AE%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%EF%BC%88%E8%8B%A5%E8%87%AA%E5%8A%A8%E6%B7%BB%E5%8A%A0%E5%A4%B1%E8%B4%A5%EF%BC%89%EF%BC%9A%E2%80%8B\">3.\u914d\u7f6e\u73af\u5883\u53d8\u91cf&#xff08;\u82e5\u81ea\u52a8\u6dfb\u52a0\u5931\u8d25&#xff09;&#xff1a;\u200b<\/h4>\n<p>\u867d\u7136\u5728\u5b89\u88c5\u65f6\u52fe\u9009 \u201cAdd Python 3.x to PATH\u201d \u9009\u9879\u4f1a\u81ea\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf&#xff0c;\u4f46\u6709\u65f6\u53ef\u80fd\u4f1a\u51fa\u73b0\u610f\u5916\u60c5\u51b5\u5bfc\u81f4\u914d\u7f6e\u5931\u8d25\u3002\u8fd9\u65f6&#xff0c;\u6211\u4eec\u5c31\u9700\u8981\u624b\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u200b<\/p>\n<p>\u5728 Windows \u7cfb\u7edf\u4e2d&#xff0c;\u53f3\u952e\u70b9\u51fb \u201c\u6b64\u7535\u8111\u201d&#xff0c;\u9009\u62e9 \u201c\u5c5e\u6027\u201d&#xff0c;\u7136\u540e\u70b9\u51fb \u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d&#xff0c;\u5728\u5f39\u51fa\u7684\u7a97\u53e3\u4e2d\u70b9\u51fb \u201c\u73af\u5883\u53d8\u91cf\u201d \u6309\u94ae\u3002\u5728 \u201c\u7cfb\u7edf\u53d8\u91cf\u201d \u4e2d\u627e\u5230 \u201cPath\u201d \u53d8\u91cf&#xff0c;\u70b9\u51fb \u201c\u7f16\u8f91\u201d&#xff0c;\u5728\u5f39\u51fa\u7684\u7f16\u8f91\u73af\u5883\u53d8\u91cf\u7a97\u53e3\u4e2d&#xff0c;\u70b9\u51fb \u201c\u65b0\u5efa\u201d&#xff0c;\u5c06 Python \u7684\u5b89\u88c5\u8def\u5f84\u6dfb\u52a0\u8fdb\u53bb\u3002\u4f8b\u5982&#xff0c;\u5982\u679c\u4f60\u7684 Python \u5b89\u88c5\u5728 \u201cC:\\\\Python310\u201d&#xff0c;\u5c31\u5c06 \u201cC:\\\\Python310\u201d \u548c \u201cC:\\\\Python310\\\\Scripts\u201d \u6dfb\u52a0\u5230 Path \u53d8\u91cf\u4e2d&#xff08;\u6ce8\u610f&#xff1a;\u5982\u679c\u4f60\u7684\u5b89\u88c5\u8def\u5f84\u4e0d\u540c&#xff0c;\u8bf7\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u4fee\u6539&#xff09;\u3002\u6dfb\u52a0\u5b8c\u6210\u540e&#xff0c;\u4e00\u8def\u70b9\u51fb \u201c\u786e\u5b9a\u201d \u4fdd\u5b58\u8bbe\u7f6e\u3002\u200b<\/p>\n<p>\u5728 Mac OS \u7cfb\u7edf\u4e2d&#xff0c;\u6253\u5f00 \u201c\u7ec8\u7aef\u201d \u5e94\u7528&#xff0c;\u7f16\u8f91.bash_profile\u6587\u4ef6&#xff08;\u5982\u679c\u6ca1\u6709\u8be5\u6587\u4ef6&#xff0c;\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a&#xff09;\u3002\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165nano ~\/.bash_profile&#xff0c;\u7136\u540e\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0export PATH&#061;&#034;\/Library\/Frameworks\/Python.framework\/Versions\/3.10\/bin:$PATH&#034;&#xff08;\u540c\u6837&#xff0c;\u8fd9\u91cc\u7684\u8def\u5f84\u8981\u6839\u636e\u4f60\u5b9e\u9645\u5b89\u88c5\u7684 Python \u7248\u672c\u548c\u8def\u5f84\u8fdb\u884c\u4fee\u6539&#xff09;&#xff0c;\u4fdd\u5b58\u5e76\u9000\u51fa\u6587\u4ef6&#xff08;\u6309Ctrl&#043;X&#xff0c;\u7136\u540e\u6309Y&#xff0c;\u6700\u540e\u6309Enter&#xff09;\u3002\u6700\u540e&#xff0c;\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165source ~\/.bash_profile\u4f7f\u914d\u7f6e\u751f\u6548\u3002\u200b<\/p>\n<p>\u5b8c\u6210\u4ee5\u4e0a\u6b65\u9aa4\u540e&#xff0c;\u6253\u5f00\u547d\u4ee4\u884c&#xff08;Windows \u4e0b\u6309Win&#043;R&#xff0c;\u8f93\u5165cmd\u5e76\u56de\u8f66&#xff1b;Mac OS \u4e0b\u6253\u5f00 \u201c\u7ec8\u7aef\u201d&#xff09;&#xff0c;\u8f93\u5165python &#8211;version&#xff0c;\u5982\u679c\u663e\u793a\u51fa\u4f60\u5b89\u88c5\u7684 Python \u7248\u672c\u53f7&#xff0c;\u606d\u559c\u4f60&#xff0c;Python \u73af\u5883\u642d\u5efa\u6210\u529f&#xff01;\u200b<\/p>\n<h3 id=\"%EF%BC%88%E4%BA%8C%EF%BC%89%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7%E6%8E%A8%E8%8D%90%E2%80%8B\">&#xff08;\u4e8c&#xff09;\u5f00\u53d1\u5de5\u5177\u63a8\u8350\u200b<\/h3>\n<p>\u62e5\u6709\u4e86 Python \u73af\u5883&#xff0c;\u8fd8\u9700\u8981\u4e00\u6b3e\u79f0\u624b\u7684\u5f00\u53d1\u5de5\u5177&#xff0c;\u5c31\u50cf\u6218\u58eb\u9700\u8981\u4e00\u628a\u950b\u5229\u7684\u5b9d\u5251\u4e00\u6837\u3002\u4ee5\u4e0b\u4e24\u6b3e\u5de5\u5177\u5728 Python \u722c\u866b\u5f00\u53d1\u4e2d\u5907\u53d7\u9752\u7750&#xff1a;\u200b<\/p>\n<h4 id=\"1.PyCharm%EF%BC%9A%E2%80%8B\">1.PyCharm&#xff1a;\u200b<\/h4>\n<p>PyCharm \u662f\u7531 JetBrains \u516c\u53f8\u5f00\u53d1\u7684\u4e00\u6b3e\u4e13\u95e8\u9488\u5bf9 Python \u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883&#xff08;IDE&#xff09;&#xff0c;\u529f\u80fd\u5f3a\u5927\u5230\u8d85\u4e4e\u60f3\u8c61&#xff0c;\u582a\u79f0 Python \u5f00\u53d1\u8005\u7684 \u201c\u745e\u58eb\u519b\u5200\u201d\u3002\u5b83\u62e5\u6709\u667a\u80fd\u4ee3\u7801\u8865\u5168\u529f\u80fd&#xff0c;\u5f53\u4f60\u8f93\u5165\u4ee3\u7801\u65f6&#xff0c;\u5b83\u80fd\u81ea\u52a8\u63d0\u793a\u53ef\u80fd\u7684\u51fd\u6570\u3001\u53d8\u91cf\u548c\u65b9\u6cd5&#xff0c;\u5927\u5927\u63d0\u9ad8\u4e86\u7f16\u7801\u6548\u7387&#xff0c;\u5c31\u50cf\u6709\u4e00\u4e2a\u8d34\u5fc3\u7684\u5c0f\u52a9\u624b\u5728\u65c1\u8fb9\u968f\u65f6\u63d0\u9192\u4f60\u4e00\u6837\u3002\u6bd4\u5982&#xff0c;\u5f53\u4f60\u8f93\u5165requests.ge&#xff0c;\u5b83\u4f1a\u81ea\u52a8\u63d0\u793arequests.get\u65b9\u6cd5&#xff0c;\u4f60\u53ea\u9700\u6309\u4e0b\u56de\u8f66\u952e\u5c31\u80fd\u5feb\u901f\u5b8c\u6210\u8f93\u5165\u3002\u200b<\/p>\n<p>\u5b83\u8fd8\u5177\u5907\u5f3a\u5927\u7684\u4ee3\u7801\u5206\u6790\u548c\u8c03\u8bd5\u5de5\u5177\u3002\u5728\u8c03\u8bd5\u722c\u866b\u7a0b\u5e8f\u65f6&#xff0c;\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u65ad\u70b9&#xff0c;\u9010\u884c\u6267\u884c\u4ee3\u7801&#xff0c;\u89c2\u5bdf\u53d8\u91cf\u7684\u503c\u548c\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u7a0b&#xff0c;\u8f7b\u677e\u627e\u51fa\u4ee3\u7801\u4e2d\u7684\u95ee\u9898\u3002\u800c\u4e14&#xff0c;PyCharm \u652f\u6301\u591a\u79cd Python \u6846\u67b6\u548c\u5e93&#xff0c;\u5bf9\u4e8e\u722c\u866b\u5f00\u53d1\u4e2d\u5e38\u7528\u7684requests\u3001BeautifulSoup\u7b49\u5e93\u90fd\u6709\u5f88\u597d\u7684\u652f\u6301&#xff0c;\u8ba9\u4f60\u53ef\u4ee5\u65e0\u7f1d\u96c6\u6210\u5404\u79cd\u5de5\u5177\u8fdb\u884c\u5f00\u53d1\u3002\u6b64\u5916&#xff0c;\u5b83\u8fd8\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u63d2\u4ef6\u5e02\u573a&#xff0c;\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u5b89\u88c5\u5404\u79cd\u63d2\u4ef6&#xff0c;\u8fdb\u4e00\u6b65\u6269\u5c55\u5176\u529f\u80fd\u3002\u200b<\/p>\n<p>PyCharm \u9002\u7528\u4e8e\u5404\u79cd\u89c4\u6a21\u7684\u9879\u76ee\u5f00\u53d1&#xff0c;\u65e0\u8bba\u662f\u5c0f\u578b\u7684\u4e2a\u4eba\u722c\u866b\u9879\u76ee&#xff0c;\u8fd8\u662f\u5927\u578b\u7684\u4f01\u4e1a\u7ea7\u6570\u636e\u91c7\u96c6\u7cfb\u7edf&#xff0c;\u5b83\u90fd\u80fd\u6e38\u5203\u6709\u4f59\u5730\u5e94\u5bf9\u3002\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bf4&#xff0c;\u5b83\u53cb\u597d\u7684\u754c\u9762\u548c\u8be6\u7ec6\u7684\u63d0\u793a\u4fe1\u606f\u4e5f\u80fd\u5e2e\u52a9\u5feb\u901f\u4e0a\u624b\u3002\u200b<\/p>\n<h4 id=\"2.Jupyter%20Notebook%EF%BC%9A%E2%80%8B\">2.Jupyter Notebook&#xff1a;\u200b<\/h4>\n<p>Jupyter Notebook \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u4ea4\u4e92\u5f0f\u8ba1\u7b97\u73af\u5883&#xff0c;\u5b83\u4ee5\u4e00\u79cd\u72ec\u7279\u7684\u65b9\u5f0f\u5c55\u793a\u4ee3\u7801\u548c\u7ed3\u679c&#xff0c;\u5c31\u50cf\u662f\u4e00\u4e2a\u53ef\u4ee5\u5b9e\u65f6\u4ea4\u4e92\u7684\u7b14\u8bb0\u672c\u3002\u5728 Jupyter Notebook \u4e2d&#xff0c;\u4f60\u53ef\u4ee5\u5c06\u4ee3\u7801\u3001\u6587\u672c\u3001\u56fe\u50cf\u3001\u6570\u5b66\u516c\u5f0f\u7b49\u591a\u79cd\u5143\u7d20\u7ec4\u5408\u5728\u4e00\u4e2a\u6587\u6863\u4e2d&#xff0c;\u5e76\u4e14\u53ef\u4ee5\u9010\u884c\u8fd0\u884c\u4ee3\u7801&#xff0c;\u7acb\u5373\u770b\u5230\u7ed3\u679c&#xff0c;\u8fd9\u79cd\u4ea4\u4e92\u5f0f\u7684\u4f53\u9a8c\u975e\u5e38\u9002\u5408\u5feb\u901f\u9a8c\u8bc1\u60f3\u6cd5\u3001\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316&#xff0c;\u4ee5\u53ca\u6559\u5b66\u6f14\u793a\u3002\u200b<\/p>\n<p>\u4f8b\u5982&#xff0c;\u5728\u8fdb\u884c\u722c\u866b\u5f00\u53d1\u65f6&#xff0c;\u4f60\u53ef\u4ee5\u5148\u5728 Jupyter Notebook \u4e2d\u7f16\u5199\u4e00\u5c0f\u6bb5\u4ee3\u7801\u6765\u6d4b\u8bd5\u7f51\u9875\u8bf7\u6c42\u662f\u5426\u6210\u529f&#xff0c;\u7136\u540e\u9010\u6b65\u6dfb\u52a0\u4ee3\u7801\u8fdb\u884c\u6570\u636e\u89e3\u6790\u548c\u63d0\u53d6&#xff0c;\u6bcf\u4e00\u6b65\u7684\u7ed3\u679c\u90fd\u80fd\u76f4\u89c2\u5730\u5c55\u793a\u51fa\u6765&#xff0c;\u65b9\u4fbf\u4f60\u968f\u65f6\u8c03\u6574\u548c\u4f18\u5316\u4ee3\u7801\u3002\u5b83\u8fd8\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00&#xff0c;\u4e0d\u8fc7\u6211\u4eec\u4e3b\u8981\u4f7f\u7528\u5b83\u6765\u8fdb\u884c Python \u7f16\u7a0b\u3002\u200b<\/p>\n<p>Jupyter Notebook \u7279\u522b\u9002\u5408\u6570\u636e\u79d1\u5b66\u548c\u673a\u5668\u5b66\u4e60\u9886\u57df\u7684\u9879\u76ee&#xff0c;\u4ee5\u53ca\u9700\u8981\u9891\u7e41\u8fdb\u884c\u4ee3\u7801\u6d4b\u8bd5\u548c\u63a2\u7d22\u6027\u5f00\u53d1\u7684\u573a\u666f\u3002\u5b83\u7684\u5206\u4eab\u548c\u534f\u4f5c\u529f\u80fd\u4e5f\u975e\u5e38\u5f3a\u5927&#xff0c;\u4f60\u53ef\u4ee5\u5c06\u6574\u4e2a Notebook \u6587\u4ef6\u5206\u4eab\u7ed9\u4ed6\u4eba&#xff0c;\u4ed6\u4eba\u53ef\u4ee5\u76f4\u63a5\u5728\u81ea\u5df1\u7684\u73af\u5883\u4e2d\u6253\u5f00\u5e76\u8fd0\u884c&#xff0c;\u65b9\u4fbf\u56e2\u961f\u4e4b\u95f4\u7684\u4ea4\u6d41\u548c\u5408\u4f5c\u3002\u200b<\/p>\n<h3 id=\"%EF%BC%88%E4%B8%89%EF%BC%89%E5%BF%85%E5%A4%87%E5%BA%93%E5%AE%89%E8%A3%85%E2%80%8B\">&#xff08;\u4e09&#xff09;\u5fc5\u5907\u5e93\u5b89\u88c5\u200b<\/h3>\n<p>Python \u7684\u5f3a\u5927\u79bb\u4e0d\u5f00\u5404\u79cd\u4e30\u5bcc\u7684\u5e93&#xff0c;\u5bf9\u4e8e\u7f51\u7edc\u722c\u866b\u6765\u8bf4&#xff0c;\u4ee5\u4e0b\u51e0\u4e2a\u5e93\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684 \u201c\u79d8\u5bc6\u6b66\u5668\u201d&#xff1a;\u200b<\/p>\n<h4 id=\"1.requests%20%E5%BA%93%EF%BC%9A%E2%80%8B\">1.requests \u5e93&#xff1a;\u200b<\/h4>\n<p>requests \u5e93\u662f Python \u4e2d\u6700\u5e38\u7528\u7684 HTTP \u8bf7\u6c42\u5e93&#xff0c;\u5b83\u7684\u4f7f\u547d\u5c31\u662f\u8ba9 HTTP \u8bf7\u6c42\u53d8\u5f97\u7b80\u5355\u800c\u4f18\u96c5\u3002\u4f7f\u7528\u5b83&#xff0c;\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u53d1\u9001\u5404\u79cd\u7c7b\u578b\u7684 HTTP \u8bf7\u6c42&#xff0c;\u5982 GET\u3001POST\u3001PUT\u3001DELETE \u7b49&#xff0c;\u5c31\u50cf\u7ed9\u7f51\u9875\u670d\u52a1\u5668\u53d1\u9001\u4e00\u5c01\u7b80\u5355\u7684\u4fe1\u4ef6\u4e00\u6837\u5bb9\u6613\u3002\u4f8b\u5982&#xff0c;\u4f7f\u7528requests.get(url)\u5c31\u53ef\u4ee5\u5411\u6307\u5b9a\u7684url\u53d1\u9001\u4e00\u4e2a GET \u8bf7\u6c42&#xff0c;\u83b7\u53d6\u7f51\u9875\u7684\u5185\u5bb9&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>import requests<\/p>\n<p>url &#061; &#039;https:\/\/www.example.com&#039;<br \/>\nresponse &#061; requests.get(url)<br \/>\nif response.status_code &#061;&#061; 200:<br \/>\n    print(response.text)<br \/>\nelse:<br \/>\n    print(f&#034;\u8bf7\u6c42\u5931\u8d25&#xff0c;\u72b6\u6001\u7801&#xff1a;{response.status_code}&#034;)<\/p>\n<p>\u5b89\u88c5 requests \u5e93\u975e\u5e38\u7b80\u5355&#xff0c;\u6253\u5f00\u547d\u4ee4\u884c&#xff0c;\u8f93\u5165pip install requests\u5373\u53ef\u5b8c\u6210\u5b89\u88c5\u3002\u5982\u679c\u4f60\u7684\u7f51\u7edc\u8fde\u63a5\u8f83\u6162&#xff0c;\u53ef\u80fd\u9700\u8981\u8bbe\u7f6e\u4e00\u4e0b\u8d85\u65f6\u65f6\u95f4&#xff0c;\u6bd4\u5982pip &#8211;default-timeout&#061;100 install requests \u3002\u200b<\/p>\n<h4 id=\"2.BeautifulSoup4%20%E5%BA%93%EF%BC%9A%E2%80%8B\">2.BeautifulSoup4 \u5e93&#xff1a;\u200b<\/h4>\n<p>BeautifulSoup4&#xff08;\u7b80\u79f0bs4&#xff09;\u662f\u4e00\u4e2a\u7528\u4e8e\u89e3\u6790 HTML \u548c XML \u6587\u6863\u7684\u5e93&#xff0c;\u5b83\u5c31\u50cf\u4e00\u628a\u795e\u5947\u7684\u624b\u672f\u5200&#xff0c;\u80fd\u591f\u5c06\u590d\u6742\u7684\u7f51\u9875\u7ed3\u6784\u89e3\u6790\u6210\u4e00\u4e2a\u6613\u4e8e\u64cd\u4f5c\u7684\u6811\u5f62\u7ed3\u6784&#xff0c;\u8ba9\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u63d0\u53d6\u51fa\u6240\u9700\u7684\u6570\u636e\u3002\u6bd4\u5982&#xff0c;\u4f60\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u67e5\u627e\u7f51\u9875\u4e2d\u7684\u6240\u6709\u94fe\u63a5\u3001\u63d0\u53d6\u7279\u5b9a\u6807\u7b7e\u7684\u5185\u5bb9\u7b49\u3002\u200b<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b&#xff0c;\u4f7f\u7528BeautifulSoup4\u89e3\u6790 HTML \u6587\u6863\u5e76\u63d0\u53d6\u6240\u6709\u94fe\u63a5&#xff1a;<\/p>\n<p>from bs4 import BeautifulSoup<\/p>\n<p>html &#061; &#034;&#034;&#034;<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n    &lt;title&gt;\u793a\u4f8b\u7f51\u9875&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n    &lt;a href&#061;&#034;https:\/\/www.example1.com&#034;&gt;\u94fe\u63a51&lt;\/a&gt;<br \/>\n    &lt;a href&#061;&#034;https:\/\/www.example2.com&#034;&gt;\u94fe\u63a52&lt;\/a&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<br \/>\n&#034;&#034;&#034;<\/p>\n<p>soup &#061; BeautifulSoup(html, &#039;html.parser&#039;)<br \/>\nlinks &#061; soup.find_all(&#039;a&#039;)<br \/>\nfor link in links:<br \/>\n    print(link.get(&#039;href&#039;))<\/p>\n<p>\u5b89\u88c5BeautifulSoup4\u5e93\u540c\u6837\u4f7f\u7528 pip \u547d\u4ee4&#xff1a;pip install beautifulsoup4 \u3002\u6b64\u5916&#xff0c;\u8fd8\u9700\u8981\u5b89\u88c5\u4e00\u4e2a\u89e3\u6790\u5668&#xff0c;\u5e38\u7528\u7684\u89e3\u6790\u5668\u6709lxml\u548chtml.parser&#xff0c;\u53ef\u4ee5\u901a\u8fc7pip install lxml\u6216pip install html.parser\u6765\u5b89\u88c5\u3002\u200b<\/p>\n<h4 id=\"3.Scrapy%20%E6%A1%86%E6%9E%B6%EF%BC%9A%E2%80%8B\">3.Scrapy \u6846\u67b6&#xff1a;\u200b<\/h4>\n<p>Scrapy \u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u722c\u866b\u6846\u67b6&#xff0c;\u5b83\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u5957\u5b8c\u6574\u7684\u722c\u866b\u89e3\u51b3\u65b9\u6848&#xff0c;\u5c31\u50cf\u4e00\u4e2a\u88c5\u5907\u7cbe\u826f\u7684\u6218\u6597\u56e2\u961f&#xff0c;\u80fd\u591f\u5e2e\u52a9\u6211\u4eec\u9ad8\u6548\u5730\u6784\u5efa\u5927\u578b\u3001\u590d\u6742\u7684\u722c\u866b\u7cfb\u7edf\u3002Scrapy \u5177\u6709\u5206\u5e03\u5f0f\u722c\u53d6\u7684\u80fd\u529b&#xff0c;\u53ef\u4ee5\u5229\u7528\u591a\u53f0\u8ba1\u7b97\u673a\u540c\u65f6\u8fdb\u884c\u6570\u636e\u91c7\u96c6&#xff0c;\u5927\u5927\u63d0\u9ad8\u4e86\u722c\u53d6\u6548\u7387&#xff1b;\u5b83\u8fd8\u81ea\u5e26\u4e86\u81ea\u52a8\u5904\u7406\u8bf7\u6c42\u961f\u5217\u3001\u4e2d\u95f4\u4ef6\u673a\u5236\u7b49\u529f\u80fd&#xff0c;\u4f7f\u5f97\u722c\u866b\u7684\u7ba1\u7406\u548c\u6269\u5c55\u66f4\u52a0\u65b9\u4fbf\u3002\u200b<\/p>\n<p>\u4f7f\u7528 Scrapy \u6846\u67b6&#xff0c;\u4f60\u9700\u8981\u5b9a\u4e49\u722c\u866b\u7c7b&#xff0c;\u6307\u5b9a\u8981\u722c\u53d6\u7684\u7f51\u7ad9\u3001\u89e3\u6790\u89c4\u5219\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684 Scrapy \u722c\u866b\u793a\u4f8b&#xff1a;<\/p>\n<p>import scrapy<\/p>\n<p>class ExampleSpider(scrapy.Spider):<br \/>\n    name &#061; &#039;example&#039;<br \/>\n    start_urls &#061; [<br \/>\n        &#039;https:\/\/www.example.com&#039;,<br \/>\n    ]<\/p>\n<p>    def parse(self, response):<br \/>\n        for item in response.css(&#039;div.item&#039;):<br \/>\n            yield {<br \/>\n                &#039;title&#039;: item.css(&#039;h2.title::text&#039;).get(),<br \/>\n                &#039;link&#039;: item.css(&#039;a::attr(href)&#039;).get(),<br \/>\n            }<\/p>\n<p>\u5b89\u88c5 Scrapy \u6846\u67b6&#xff1a;pip install scrapy \u3002\u200b<\/p>\n<h4 id=\"4.Selenium%20%E5%BA%93%EF%BC%9A%E2%80%8B\">4.Selenium \u5e93&#xff1a;\u200b<\/h4>\n<p>Selenium \u5e93\u4e3b\u8981\u7528\u4e8e\u81ea\u52a8\u5316\u6d4b\u8bd5&#xff0c;\u4f46\u5728\u722c\u866b\u9886\u57df\u4e5f\u6709\u7740\u91cd\u8981\u7684\u5e94\u7528\u3002\u5b83\u53ef\u4ee5\u6a21\u62df\u4eba\u7c7b\u5728\u6d4f\u89c8\u5668\u4e2d\u7684\u64cd\u4f5c&#xff0c;\u5982\u70b9\u51fb\u6309\u94ae\u3001\u8f93\u5165\u6587\u672c\u3001\u6eda\u52a8\u9875\u9762\u7b49&#xff0c;\u8fd9\u5bf9\u4e8e\u4e00\u4e9b\u9700\u8981\u4ea4\u4e92\u624d\u80fd\u83b7\u53d6\u6570\u636e\u7684\u7f51\u7ad9\u975e\u5e38\u6709\u7528\u3002\u6bd4\u5982&#xff0c;\u6709\u4e9b\u7f51\u7ad9\u7684\u6570\u636e\u662f\u901a\u8fc7 JavaScript \u52a8\u6001\u52a0\u8f7d\u7684&#xff0c;\u4f7f\u7528\u666e\u901a\u7684\u722c\u866b\u5e93\u65e0\u6cd5\u76f4\u63a5\u83b7\u53d6&#xff0c;\u8fd9\u65f6\u5c31\u53ef\u4ee5\u501f\u52a9 Selenium \u5e93\u6765\u9a71\u52a8\u6d4f\u89c8\u5668&#xff0c;\u6a21\u62df\u7528\u6237\u64cd\u4f5c&#xff0c;\u4ece\u800c\u83b7\u53d6\u5230\u5b8c\u6574\u7684\u6570\u636e\u3002\u200b<\/p>\n<p>\u4f7f\u7528 Selenium \u5e93\u9700\u8981\u5148\u5b89\u88c5\u6d4f\u89c8\u5668\u9a71\u52a8&#xff0c;\u4f8b\u5982 Chrome \u6d4f\u89c8\u5668\u9700\u8981\u4e0b\u8f7d ChromeDriver\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 Selenium \u6253\u5f00\u7f51\u9875\u5e76\u83b7\u53d6\u6807\u9898\u7684\u793a\u4f8b&#xff1a;<\/p>\n<p>from selenium import webdriver<\/p>\n<p>driver &#061; webdriver.Chrome()<br \/>\ndriver.get(&#039;https:\/\/www.example.com&#039;)<br \/>\nprint(driver.title)<br \/>\ndriver.quit()<\/p>\n<p>\u5b89\u88c5 Selenium \u5e93&#xff1a;pip install selenium \u3002\u200b<\/p>\n<h2 id=\"%E4%B8%89%E3%80%81%E7%88%AC%E8%99%AB%E5%8E%9F%E7%90%86%E5%89%96%E6%9E%90%EF%BC%9A%E6%8E%A2%E5%AF%BB%E5%86%85%E5%9C%A8%E6%9C%BA%E5%88%B6%E2%80%8B\">\u4e09\u3001\u722c\u866b\u539f\u7406\u5256\u6790&#xff1a;\u63a2\u5bfb\u5185\u5728\u673a\u5236\u200b<\/h2>\n<h3 id=\"%EF%BC%88%E4%B8%80%EF%BC%89%E5%8F%91%E8%B5%B7%E8%AF%B7%E6%B1%82%E2%80%8B\">&#xff08;\u4e00&#xff09;\u53d1\u8d77\u8bf7\u6c42\u200b<\/h3>\n<p>\u5f53\u6211\u4eec\u4f7f\u7528\u722c\u866b\u83b7\u53d6\u7f51\u9875\u6570\u636e\u65f6&#xff0c;\u9996\u5148\u8981\u505a\u7684\u5c31\u662f\u53d1\u8d77\u8bf7\u6c42&#xff0c;\u8fd9\u5c31\u597d\u6bd4\u6211\u4eec\u53bb\u670b\u53cb\u5bb6\u62dc\u8bbf&#xff0c;\u9700\u8981\u5148\u6572\u6572\u95e8\u8be2\u95ee\u662f\u5426\u53ef\u4ee5\u8fdb\u5165\u3002\u722c\u866b\u901a\u8fc7 HTTP \u534f\u8bae\u5411\u76ee\u6807\u7f51\u7ad9\u7684\u670d\u52a1\u5668\u53d1\u9001\u8bf7\u6c42&#xff0c;\u8bf7\u6c42\u4e2d\u5305\u542b\u4e86\u5f88\u591a\u4fe1\u606f&#xff0c;\u5982\u8bf7\u6c42\u7684\u7f51\u5740&#xff08;URL&#xff09;\u3001\u8bf7\u6c42\u65b9\u6cd5&#xff08;GET\u3001POST \u7b49&#xff09;\u3001\u8bf7\u6c42\u5934&#xff08;Headers&#xff09;\u7b49 \u3002\u200b<\/p>\n<p>\u5176\u4e2d&#xff0c;URL \u5c31\u50cf\u662f\u670b\u53cb\u5bb6\u7684\u5730\u5740&#xff0c;\u660e\u786e\u544a\u8bc9\u722c\u866b\u8981\u8bbf\u95ee\u54ea\u4e2a\u7f51\u9875&#xff1b;\u8bf7\u6c42\u65b9\u6cd5\u5219\u51b3\u5b9a\u4e86\u6211\u4eec\u4ee5\u4f55\u79cd\u65b9\u5f0f\u4e0e\u670d\u52a1\u5668 \u201c\u4ea4\u6d41\u201d&#xff0c;GET \u65b9\u6cd5\u901a\u5e38\u7528\u4e8e\u83b7\u53d6\u7f51\u9875\u7684\u57fa\u672c\u4fe1\u606f&#xff0c;\u5c31\u50cf\u6211\u4eec\u7b80\u5355\u5730\u8be2\u95ee\u670b\u53cb\u5bb6\u91cc\u7684\u60c5\u51b5&#xff1b;POST \u65b9\u6cd5\u5219\u66f4\u50cf\u662f\u5e26\u7740\u793c\u7269\u53bb\u670b\u53cb\u5bb6&#xff0c;\u5b83\u53ef\u4ee5\u5411\u670d\u52a1\u5668\u53d1\u9001\u4e00\u4e9b\u6570\u636e&#xff0c;\u6bd4\u5982\u767b\u5f55\u8868\u5355\u4e2d\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u7b49\u3002\u8bf7\u6c42\u5934\u5219\u5305\u542b\u4e86\u66f4\u591a\u5173\u4e8e\u8bf7\u6c42\u7684\u7ec6\u8282\u4fe1\u606f&#xff0c;\u4f8b\u5982\u6211\u4eec\u4f7f\u7528\u7684\u6d4f\u89c8\u5668\u7c7b\u578b\u3001\u64cd\u4f5c\u7cfb\u7edf\u7b49&#xff0c;\u8fd9\u4e9b\u4fe1\u606f\u5c31\u50cf\u662f\u6211\u4eec\u53bb\u670b\u53cb\u5bb6\u65f6\u7684\u81ea\u6211\u4ecb\u7ecd&#xff0c;\u8ba9\u670d\u52a1\u5668\u80fd\u591f\u66f4\u597d\u5730 \u201c\u4e86\u89e3\u201d \u6211\u4eec\u7684\u8bf7\u6c42\u3002\u200b<\/p>\n<p>\u4ee5\u4f7f\u7528requests\u5e93\u53d1\u9001 GET \u8bf7\u6c42\u4e3a\u4f8b&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>import requests<\/p>\n<p>url &#061; &#039;https:\/\/www.example.com&#039;<br \/>\nheaders &#061; {<br \/>\n    &#039;User-Agent&#039;: &#039;Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/91.0.4472.124 Safari\/537.36&#039;<br \/>\n}<br \/>\nresponse &#061; requests.get(url, headers&#061;headers)<\/p>\n<p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d&#xff0c;\u6211\u4eec\u5b9a\u4e49\u4e86\u8981\u8bbf\u95ee\u7684url&#xff0c;\u5e76\u8bbe\u7f6e\u4e86headers&#xff0c;\u6a21\u62df\u4e86\u4e00\u4e2a Chrome \u6d4f\u89c8\u5668\u7684\u8bf7\u6c42\u5934&#xff0c;\u7136\u540e\u4f7f\u7528requests.get()\u65b9\u6cd5\u53d1\u9001\u8bf7\u6c42&#xff0c;\u670d\u52a1\u5668\u4f1a\u6839\u636e\u8fd9\u4e2a\u8bf7\u6c42\u8fd4\u56de\u76f8\u5e94\u7684\u5185\u5bb9\u3002\u200b<\/p>\n<h3 id=\"%EF%BC%88%E4%BA%8C%EF%BC%89%E8%8E%B7%E5%8F%96%E5%93%8D%E5%BA%94%E2%80%8B\">&#xff08;\u4e8c&#xff09;\u83b7\u53d6\u54cd\u5e94\u200b<\/h3>\n<p>\u5f53\u722c\u866b\u53d1\u9001\u8bf7\u6c42\u540e&#xff0c;\u670d\u52a1\u5668\u4f1a\u5bf9\u8fd9\u4e2a\u8bf7\u6c42\u8fdb\u884c\u5904\u7406&#xff0c;\u5e76\u8fd4\u56de\u4e00\u4e2a\u54cd\u5e94&#xff08;Response&#xff09;\u3002\u8fd9\u4e2a\u54cd\u5e94\u5c31\u50cf\u662f\u670b\u53cb\u4ece\u623f\u95f4\u91cc\u9012\u7ed9\u6211\u4eec\u7684\u4e1c\u897f&#xff0c;\u91cc\u9762\u5305\u542b\u4e86\u6211\u4eec\u8bf7\u6c42\u7684\u7f51\u9875\u5185\u5bb9\u3002\u54cd\u5e94\u5185\u5bb9\u53ef\u80fd\u662f HTML \u683c\u5f0f\u7684\u6587\u672c&#xff0c;\u8fd9\u5c31\u50cf\u662f\u4e00\u4efd\u8be6\u7ec6\u7684\u623f\u5c4b\u5e03\u5c40\u56fe&#xff0c;\u63cf\u8ff0\u4e86\u7f51\u9875\u7684\u7ed3\u6784\u548c\u5c55\u793a\u5185\u5bb9&#xff1b;\u4e5f\u53ef\u80fd\u662f JSON \u683c\u5f0f\u7684\u6570\u636e&#xff0c;\u66f4\u50cf\u662f\u4e00\u4efd\u7b80\u6d01\u7684\u7269\u54c1\u6e05\u5355&#xff0c;\u4ee5\u4e00\u79cd\u7ed3\u6784\u5316\u7684\u65b9\u5f0f\u5b58\u50a8\u7740\u6570\u636e&#xff1b;\u8fd8\u53ef\u80fd\u662f\u4e8c\u8fdb\u5236\u6570\u636e&#xff0c;\u6bd4\u5982\u56fe\u7247\u3001\u89c6\u9891\u7b49&#xff0c;\u5c31\u50cf\u670b\u53cb\u7ed9\u6211\u4eec\u7684\u4e00\u4e9b\u5b9e\u4f53\u7269\u54c1\u3002\u200b<\/p>\n<p>\u5728 Python \u4e2d&#xff0c;\u4f7f\u7528requests\u5e93\u53d1\u9001\u8bf7\u6c42\u540e&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7response\u5bf9\u8c61\u6765\u83b7\u53d6\u54cd\u5e94\u7684\u5404\u79cd\u4fe1\u606f\u3002\u4f8b\u5982&#xff0c;\u901a\u8fc7response.status_code\u53ef\u4ee5\u83b7\u53d6\u54cd\u5e94\u7684\u72b6\u6001\u7801&#xff0c;200 \u8868\u793a\u8bf7\u6c42\u6210\u529f&#xff0c;\u5c31\u50cf\u670b\u53cb\u6109\u5feb\u5730\u5f00\u95e8\u8fce\u63a5\u6211\u4eec&#xff1b;404 \u8868\u793a\u9875\u9762\u672a\u627e\u5230&#xff0c;\u610f\u5473\u7740\u6211\u4eec\u627e\u9519\u4e86\u5730\u5740&#xff1b;500 \u8868\u793a\u670d\u52a1\u5668\u5185\u90e8\u9519\u8bef&#xff0c;\u5c31\u50cf\u662f\u670b\u53cb\u5bb6\u91cc\u51fa\u4e86\u70b9\u72b6\u51b5\u3002\u901a\u8fc7response.text\u53ef\u4ee5\u83b7\u53d6\u54cd\u5e94\u7684\u6587\u672c\u5185\u5bb9&#xff08;\u5982\u679c\u662f HTML \u9875\u9762&#xff0c;\u5c31\u662f\u9875\u9762\u7684\u6e90\u4ee3\u7801&#xff09;&#xff0c;\u901a\u8fc7response.json()\u53ef\u4ee5\u5c06 JSON \u683c\u5f0f\u7684\u54cd\u5e94\u5185\u5bb9\u89e3\u6790\u4e3a Python \u7684\u5b57\u5178\u6216\u5217\u8868\u5bf9\u8c61\u3002\u200b<\/p>\n<p>\u4ee5\u4e0b\u662f\u83b7\u53d6\u54cd\u5e94\u5185\u5bb9\u5e76\u5224\u65ad\u72b6\u6001\u7801\u7684\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>import requests<\/p>\n<p>url &#061; &#039;https:\/\/www.example.com&#039;<br \/>\nresponse &#061; requests.get(url)<\/p>\n<p>if response.status_code &#061;&#061; 200:<br \/>\n    print(&#034;\u8bf7\u6c42\u6210\u529f&#xff0c;\u7f51\u9875\u5185\u5bb9\u5982\u4e0b&#xff1a;&#034;)<br \/>\n    print(response.text)<br \/>\nelse:<br \/>\n    print(f&#034;\u8bf7\u6c42\u5931\u8d25&#xff0c;\u72b6\u6001\u7801&#xff1a;{response.status_code}&#034;)<\/p>\n<h3 id=\"%EF%BC%88%E4%B8%89%EF%BC%89%E8%A7%A3%E6%9E%90%E5%86%85%E5%AE%B9%E2%80%8B\">&#xff08;\u4e09&#xff09;\u89e3\u6790\u5185\u5bb9\u200b<\/h3>\n<p>\u83b7\u53d6\u5230\u54cd\u5e94\u5185\u5bb9\u540e&#xff0c;\u6211\u4eec\u9700\u8981\u4ece\u4e2d\u63d0\u53d6\u51fa\u6211\u4eec\u771f\u6b63\u9700\u8981\u7684\u6570\u636e&#xff0c;\u8fd9\u5c31\u597d\u6bd4\u4ece\u670b\u53cb\u7ed9\u7684\u4e1c\u897f\u91cc\u6311\u9009\u51fa\u6211\u4eec\u611f\u5174\u8da3\u7684\u7269\u54c1\u3002\u89e3\u6790\u7f51\u9875\u5185\u5bb9\u6709\u591a\u79cd\u65b9\u6cd5&#xff0c;\u5e38\u7528\u7684\u6709\u6b63\u5219\u8868\u8fbe\u5f0f\u3001BeautifulSoup\u3001XPath \u7b49\u3002\u200b<\/p>\n<p>1.\u6b63\u5219\u8868\u8fbe\u5f0f&#xff1a;\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u6587\u672c\u5339\u914d\u5de5\u5177&#xff0c;\u5b83\u4f7f\u7528\u7279\u5b9a\u7684\u5b57\u7b26\u548c\u89c4\u5219\u6765\u63cf\u8ff0\u6587\u672c\u6a21\u5f0f\u3002\u5728\u89e3\u6790\u7f51\u9875\u65f6&#xff0c;\u6211\u4eec\u53ef\u4ee5\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u5339\u914d HTML \u6587\u672c\u4e2d\u7684\u7279\u5b9a\u5185\u5bb9\u3002\u4f8b\u5982&#xff0c;\u8981\u63d0\u53d6\u7f51\u9875\u4e2d\u6240\u6709\u7684\u94fe\u63a5&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u7c7b\u4f3cr&#039;href&#061;[&#034;\\\\&#039;](.*?)[&#034;\\\\&#039;]&#039;\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u4e0d\u8fc7&#xff0c;\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u8bed\u6cd5\u76f8\u5bf9\u590d\u6742&#xff0c;\u5bf9\u4e8e\u590d\u6742\u7684\u7f51\u9875\u7ed3\u6784&#xff0c;\u7f16\u5199\u548c\u8c03\u8bd5\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u80fd\u4f1a\u6bd4\u8f83\u56f0\u96be&#xff0c;\u5c31\u50cf\u662f\u5728\u4e00\u5806\u6742\u4e71\u7684\u7269\u54c1\u4e2d\u5bfb\u627e\u7279\u5b9a\u7684\u4e1c\u897f&#xff0c;\u9700\u8981\u82b1\u8d39\u4e00\u4e9b\u5fc3\u601d\u3002\u200b<\/p>\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u63d0\u53d6\u7f51\u9875\u94fe\u63a5\u7684\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>import re<br \/>\nimport requests<\/p>\n<p>url &#061; &#039;https:\/\/www.example.com&#039;<br \/>\nresponse &#061; requests.get(url)<\/p>\n<p>if response.status_code &#061;&#061; 200:<br \/>\n    pattern &#061; re.compile(r&#039;href&#061;[&#034;\\\\&#039;](.*?)[&#034;\\\\&#039;]&#039;)<br \/>\n    links &#061; pattern.findall(response.text)<br \/>\n    for link in links:<br \/>\n        print(link)<br \/>\nelse:<br \/>\n    print(f&#034;\u8bf7\u6c42\u5931\u8d25&#xff0c;\u72b6\u6001\u7801&#xff1a;{response.status_code}&#034;)<\/p>\n<p>2.BeautifulSoup&#xff1a;BeautifulSoup \u662f\u4e00\u4e2a\u4e13\u95e8\u7528\u4e8e\u89e3\u6790 HTML \u548c XML \u6587\u6863\u7684\u5e93&#xff0c;\u5b83\u5c06\u590d\u6742\u7684\u6587\u6863\u7ed3\u6784\u8f6c\u5316\u4e3a\u4e00\u4e2a\u6613\u4e8e\u64cd\u4f5c\u7684\u6811\u5f62\u7ed3\u6784&#xff0c;\u5c31\u50cf\u628a\u4e00\u5806\u6742\u4e71\u7684\u7269\u54c1\u6574\u7406\u6210\u4e00\u4e2a\u6709\u5e8f\u7684\u8d27\u67b6&#xff0c;\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u4ece\u4e2d\u627e\u5230\u6240\u9700\u7684\u4e1c\u897f\u3002\u4f7f\u7528 BeautifulSoup&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6807\u7b7e\u540d\u3001\u5c5e\u6027\u7b49\u65b9\u5f0f\u8f7b\u677e\u5730\u67e5\u627e\u548c\u63d0\u53d6\u6570\u636e\u3002\u6bd4\u5982&#xff0c;\u4f7f\u7528soup.find_all(&#039;a&#039;)\u53ef\u4ee5\u627e\u5230\u7f51\u9875\u4e2d\u6240\u6709\u7684&lt;a&gt;\u6807\u7b7e&#xff0c;\u5373\u94fe\u63a5\u6807\u7b7e&#xff1b;\u4f7f\u7528soup.find(&#039;div&#039;, class_&#061;&#039;content&#039;)\u53ef\u4ee5\u627e\u5230 class \u4e3acontent\u7684&lt;div&gt;\u6807\u7b7e&#xff0c;\u63d0\u53d6\u5176\u4e2d\u7684\u5185\u5bb9\u3002\u200b<\/p>\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528 BeautifulSoup \u63d0\u53d6\u7f51\u9875\u94fe\u63a5\u7684\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>from bs4 import BeautifulSoup<br \/>\nimport requests<\/p>\n<p>url &#061; &#039;https:\/\/www.example.com&#039;<br \/>\nresponse &#061; requests.get(url)<\/p>\n<p>if response.status_code &#061;&#061; 200:<br \/>\n    soup &#061; BeautifulSoup(response.text, &#039;html.parser&#039;)<br \/>\n    links &#061; soup.find_all(&#039;a&#039;)<br \/>\n    for link in links:<br \/>\n        print(link.get(&#039;href&#039;))<br \/>\nelse:<br \/>\n    print(f&#034;\u8bf7\u6c42\u5931\u8d25&#xff0c;\u72b6\u6001\u7801&#xff1a;{response.status_code}&#034;)<\/p>\n<p>3.XPath&#xff1a;XPath \u662f\u4e00\u79cd\u7528\u4e8e\u5728 XML \u548c HTML \u6587\u6863\u4e2d\u5b9a\u4f4d\u8282\u70b9\u7684\u8bed\u8a00&#xff0c;\u5b83\u901a\u8fc7\u8def\u5f84\u8868\u8fbe\u5f0f\u6765\u9009\u53d6\u6587\u6863\u4e2d\u7684\u5143\u7d20&#xff0c;\u5c31\u50cf\u5728\u4e00\u4e2a\u5730\u56fe\u4e0a\u901a\u8fc7\u5750\u6807\u6765\u627e\u5230\u7279\u5b9a\u7684\u5730\u70b9\u3002\u4f8b\u5982&#xff0c;\/\/a\u8868\u793a\u9009\u53d6\u6240\u6709\u7684&lt;a&gt;\u6807\u7b7e&#xff0c;\/\/div[&#064;class&#061;&#039;content&#039;]\u8868\u793a\u9009\u53d6 class \u4e3acontent\u7684&lt;div&gt;\u6807\u7b7e\u3002XPath \u5728\u5904\u7406\u590d\u6742\u7684\u7f51\u9875\u7ed3\u6784\u65f6\u975e\u5e38\u5f3a\u5927&#xff0c;\u80fd\u591f\u51c6\u786e\u5730\u5b9a\u4f4d\u5230\u6211\u4eec\u9700\u8981\u7684\u6570\u636e\u8282\u70b9 \u3002\u200b<\/p>\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528 XPath \u63d0\u53d6\u7f51\u9875\u94fe\u63a5\u7684\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>from lxml import etree<br \/>\nimport requests<\/p>\n<p>url &#061; &#039;https:\/\/www.example.com&#039;<br \/>\nresponse &#061; requests.get(url)<\/p>\n<p>if response.status_code &#061;&#061; 200:<br \/>\n    html &#061; etree.HTML(response.text)<br \/>\n    links &#061; html.xpath(&#039;\/\/a\/&#064;href&#039;)<br \/>\n    for link in links:<br \/>\n        print(link)<br \/>\nelse:<br \/>\n    print(f&#034;\u8bf7\u6c42\u5931\u8d25&#xff0c;\u72b6\u6001\u7801&#xff1a;{response.status_code}&#034;)<\/p>\n<h3 id=\"%EF%BC%88%E5%9B%9B%EF%BC%89%E4%BF%9D%E5%AD%98%E6%95%B0%E6%8D%AE%E2%80%8B\">&#xff08;\u56db&#xff09;\u4fdd\u5b58\u6570\u636e\u200b<\/h3>\n<p>\u89e3\u6790\u51fa\u6240\u9700\u7684\u6570\u636e\u540e&#xff0c;\u6211\u4eec\u9700\u8981\u5c06\u8fd9\u4e9b\u6570\u636e\u4fdd\u5b58\u8d77\u6765&#xff0c;\u4ee5\u4fbf\u540e\u7eed\u4f7f\u7528&#xff0c;\u8fd9\u5c31\u50cf\u662f\u628a\u6311\u9009\u597d\u7684\u7269\u54c1\u59a5\u5584\u5b58\u653e\u8d77\u6765\u3002\u6570\u636e\u53ef\u4ee5\u4fdd\u5b58\u4e3a\u591a\u79cd\u683c\u5f0f&#xff0c;\u5e38\u89c1\u7684\u6709\u6587\u672c\u6587\u4ef6\u3001CSV \u6587\u4ef6\u3001\u6570\u636e\u5e93\u7b49\u3002\u200b<\/p>\n<p>1.\u4fdd\u5b58\u4e3a\u6587\u672c\u6587\u4ef6&#xff1a;\u5c06\u6570\u636e\u4fdd\u5b58\u4e3a\u6587\u672c\u6587\u4ef6\u662f\u6700\u57fa\u672c\u7684\u65b9\u5f0f&#xff0c;\u9002\u5408\u4fdd\u5b58\u4e00\u4e9b\u7b80\u5355\u7684\u6570\u636e&#xff0c;\u6bd4\u5982\u63d0\u53d6\u7684\u7f51\u9875\u6807\u9898\u3001\u6587\u672c\u5185\u5bb9\u7b49\u3002\u4f7f\u7528 Python \u7684\u5185\u7f6e\u51fd\u6570open()\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6587\u672c\u6587\u4ef6&#xff0c;\u5e76\u4f7f\u7528write()\u65b9\u6cd5\u5c06\u6570\u636e\u5199\u5165\u6587\u4ef6\u3002\u200b<\/p>\n<p>\u4ee5\u4e0b\u662f\u5c06\u63d0\u53d6\u7684\u7f51\u9875\u6807\u9898\u4fdd\u5b58\u4e3a\u6587\u672c\u6587\u4ef6\u7684\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>from bs4 import BeautifulSoup<br \/>\nimport requests<\/p>\n<p>url &#061; &#039;https:\/\/www.example.com&#039;<br \/>\nresponse &#061; requests.get(url)<\/p>\n<p>if response.status_code &#061;&#061; 200:<br \/>\n    soup &#061; BeautifulSoup(response.text, &#039;html.parser&#039;)<br \/>\n    title &#061; soup.title.string<\/p>\n<p>    with open(&#039;title.txt&#039;, &#039;w&#039;, encoding&#061;&#039;utf-8&#039;) as f:<br \/>\n        f.write(title)<br \/>\nelse:<br \/>\n    print(f&#034;\u8bf7\u6c42\u5931\u8d25&#xff0c;\u72b6\u6001\u7801&#xff1a;{response.status_code}&#034;)<\/p>\n<p>2.\u4fdd\u5b58\u4e3a CSV \u6587\u4ef6&#xff1a;CSV&#xff08;Comma-Separated Values&#xff09;\u6587\u4ef6\u662f\u4e00\u79cd\u5e38\u7528\u7684\u8868\u683c\u6570\u636e\u683c\u5f0f&#xff0c;\u9002\u5408\u4fdd\u5b58\u7ed3\u6784\u5316\u7684\u6570\u636e&#xff0c;\u6bd4\u5982\u4ece\u7f51\u9875\u4e2d\u63d0\u53d6\u7684\u5546\u54c1\u5217\u8868\u3001\u65b0\u95fb\u5217\u8868\u7b49\u3002\u4f7f\u7528 Python \u7684csv\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u6570\u636e\u4fdd\u5b58\u4e3a CSV \u6587\u4ef6\u3002\u200b<\/p>\n<p>\u4ee5\u4e0b\u662f\u5c06\u63d0\u53d6\u7684\u5546\u54c1\u4fe1\u606f\u4fdd\u5b58\u4e3a CSV \u6587\u4ef6\u7684\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>import csv<br \/>\nfrom bs4 import BeautifulSoup<br \/>\nimport requests<\/p>\n<p>url &#061; &#039;https:\/\/www.example.com\/products&#039;<br \/>\nresponse &#061; requests.get(url)<\/p>\n<p>if response.status_code &#061;&#061; 200:<br \/>\n    soup &#061; BeautifulSoup(response.text, &#039;html.parser&#039;)<br \/>\n    products &#061; []<\/p>\n<p>    for product in soup.find_all(&#039;div&#039;, class_&#061;&#039;product&#039;):<br \/>\n        name &#061; product.find(&#039;h2&#039;, class_&#061;&#039;product-name&#039;).text.strip()<br \/>\n        price &#061; product.find(&#039;span&#039;, class_&#061;&#039;product-price&#039;).text.strip()<br \/>\n        products.append([name, price])<\/p>\n<p>    with open(&#039;products.csv&#039;, &#039;w&#039;, newline&#061;&#039;&#039;, encoding&#061;&#039;utf-8&#039;) as f:<br \/>\n        writer &#061; csv.writer(f)<br \/>\n        writer.writerow([&#039;\u5546\u54c1\u540d\u79f0&#039;, &#039;\u4ef7\u683c&#039;])<br \/>\n        writer.writerows(products)<br \/>\nelse:<br \/>\n    print(f&#034;\u8bf7\u6c42\u5931\u8d25&#xff0c;\u72b6\u6001\u7801&#xff1a;{response.status_code}&#034;)<\/p>\n<p>3.\u4fdd\u5b58\u5230\u6570\u636e\u5e93&#xff1a;\u5982\u679c\u6570\u636e\u91cf\u8f83\u5927\u6216\u8005\u9700\u8981\u8fdb\u884c\u590d\u6742\u7684\u6570\u636e\u67e5\u8be2\u548c\u7ba1\u7406&#xff0c;\u5c06\u6570\u636e\u4fdd\u5b58\u5230\u6570\u636e\u5e93\u662f\u66f4\u597d\u7684\u9009\u62e9\u3002\u5e38\u89c1\u7684\u6570\u636e\u5e93\u6709 MySQL\u3001MongoDB \u7b49\u3002\u4ee5 MySQL \u4e3a\u4f8b&#xff0c;\u4f7f\u7528pymysql\u5e93\u53ef\u4ee5\u8fde\u63a5 MySQL \u6570\u636e\u5e93&#xff0c;\u5e76\u5c06\u6570\u636e\u63d2\u5165\u5230\u6570\u636e\u5e93\u8868\u4e2d\u3002\u200b<\/p>\n<p>\u4ee5\u4e0b\u662f\u5c06\u63d0\u53d6\u7684\u7528\u6237\u8bc4\u8bba\u4fdd\u5b58\u5230 MySQL \u6570\u636e\u5e93\u7684\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>import pymysql<br \/>\nfrom bs4 import BeautifulSoup<br \/>\nimport requests<\/p>\n<p>url &#061; &#039;https:\/\/www.example.com\/comments&#039;<br \/>\nresponse &#061; requests.get(url)<\/p>\n<p>if response.status_code &#061;&#061; 200:<br \/>\n    soup &#061; BeautifulSoup(response.text, &#039;html.parser&#039;)<br \/>\n    comments &#061; []<\/p>\n<p>    for comment in soup.find_all(&#039;div&#039;, class_&#061;&#039;comment&#039;):<br \/>\n        author &#061; comment.find(&#039;span&#039;, class_&#061;&#039;comment-author&#039;).text.strip()<br \/>\n        content &#061; comment.find(&#039;p&#039;, class_&#061;&#039;comment-content&#039;).text.strip()<br \/>\n        comments.append((author, content))<\/p>\n<p>    conn &#061; pymysql.connect(host&#061;&#039;localhost&#039;, user&#061;&#039;root&#039;, password&#061;&#039;password&#039;, database&#061;&#039;test&#039;)<br \/>\n    cursor &#061; conn.cursor()<\/p>\n<p>    for comment in comments:<br \/>\n        sql &#061; &#034;INSERT INTO comments (author, content) VALUES (%s, %s)&#034;<br \/>\n        cursor.execute(sql, comment)<\/p>\n<p>    conn.commit()<br \/>\n    cursor.close()<br \/>\n    conn.close()<br \/>\nelse:<br \/>\n    print(f&#034;\u8bf7\u6c42\u5931\u8d25&#xff0c;\u72b6\u6001\u7801&#xff1a;{response.status_code}&#034;)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2w\u6b21\uff0c\u70b9\u8d5e303\u6b21\uff0c\u6536\u85cf434\u6b21\u3002\u4e0d\u8fc7\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u8bed\u6cd5\u76f8\u5bf9\u590d\u6742\uff0c\u5bf9\u4e8e\u590d\u6742\u7684\u7f51\u9875\u7ed3\u6784\uff0c\u7f16\u5199\u548c\u8c03\u8bd5\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u80fd\u4f1a\u6bd4\u8f83\u56f0\u96be\uff0c\u5c31\u50cf\u662f\u5728\u4e00\u5806\u6742\u4e71\u7684\u7269\u54c1\u4e2d\u5bfb\u627e\u7279\u5b9a\u7684\u4e1c\u897f\uff0c\u9700\u8981\u82b1\u8d39\u4e00\u4e9b\u5fc3\u601d\u3002\u800c\u4e14\uff0cPython \u62e5\u6709\u5e9e\u5927\u7684\u5f00\u53d1\u8005\u793e\u533a\u548c\u4e30\u5bcc\u7684\u8d44\u6e90\uff0c\u5f53\u6211\u4eec\u5728\u5f00\u53d1\u722c\u866b\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898\u65f6\uff0c\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u5728\u793e\u533a\u4e2d\u5bfb\u6c42\u5e2e\u52a9\uff0c\u501f\u9274\u5176\u4ed6\u5f00\u53d1\u8005\u7684\u7ecf\u9a8c\u548c\u89e3\u51b3\u65b9\u6848\u3002\u5b83\u8fd8\u5177\u5907\u5f3a\u5927\u7684\u4ee3\u7801\u5206\u6790\u548c\u8c03\u8bd5\u5de5\u5177\u3002\u6bd4\u5982\uff0c\u6709\u4e9b\u7f51\u7ad9\u7684\u6570\u636e\u662f\u901a\u8fc7 JavaScript \u52a8\u6001\u52a0\u8f7d\u7684\uff0c\u4f7f\u7528\u666e\u901a\u7684\u722c\u866b\u5e93\u65e0\u6cd5\u76f4\u63a5\u83b7\u53d6\uff0c\u8fd9\u65f6\u5c31\u53ef\u4ee5\u501f\u52a9 Selenium \u5e93\u6765\u9a71\u52a8\u6d4f\u89c8\u5668\uff0c\u6a21\u62df\u7528\u6237\u64cd\u4f5c\uff0c\u4ece\u800c\u83b7\u53d6\u5230\u5b8c\u6574\u7684\u6570\u636e\u3002_pycharm\u722c\u866b\u9700\u8981\u5b89\u88c5\u54ea\u4e9b\u5e93<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81],"topic":[],"class_list":["post-12802","post","type-post","status-publish","format-standard","hentry","category-server","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python\u722c\u866b\uff1a\u5f00\u542f\u6570\u636e\u6293\u53d6\u7684\u5947\u5e7b\u4e4b\u65c5\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/12802.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python\u722c\u866b\uff1a\u5f00\u542f\u6570\u636e\u6293\u53d6\u7684\u5947\u5e7b\u4e4b\u65c5\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2w\u6b21\uff0c\u70b9\u8d5e303\u6b21\uff0c\u6536\u85cf434\u6b21\u3002\u4e0d\u8fc7\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u8bed\u6cd5\u76f8\u5bf9\u590d\u6742\uff0c\u5bf9\u4e8e\u590d\u6742\u7684\u7f51\u9875\u7ed3\u6784\uff0c\u7f16\u5199\u548c\u8c03\u8bd5\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u80fd\u4f1a\u6bd4\u8f83\u56f0\u96be\uff0c\u5c31\u50cf\u662f\u5728\u4e00\u5806\u6742\u4e71\u7684\u7269\u54c1\u4e2d\u5bfb\u627e\u7279\u5b9a\u7684\u4e1c\u897f\uff0c\u9700\u8981\u82b1\u8d39\u4e00\u4e9b\u5fc3\u601d\u3002\u800c\u4e14\uff0cPython \u62e5\u6709\u5e9e\u5927\u7684\u5f00\u53d1\u8005\u793e\u533a\u548c\u4e30\u5bcc\u7684\u8d44\u6e90\uff0c\u5f53\u6211\u4eec\u5728\u5f00\u53d1\u722c\u866b\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898\u65f6\uff0c\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u5728\u793e\u533a\u4e2d\u5bfb\u6c42\u5e2e\u52a9\uff0c\u501f\u9274\u5176\u4ed6\u5f00\u53d1\u8005\u7684\u7ecf\u9a8c\u548c\u89e3\u51b3\u65b9\u6848\u3002\u5b83\u8fd8\u5177\u5907\u5f3a\u5927\u7684\u4ee3\u7801\u5206\u6790\u548c\u8c03\u8bd5\u5de5\u5177\u3002\u6bd4\u5982\uff0c\u6709\u4e9b\u7f51\u7ad9\u7684\u6570\u636e\u662f\u901a\u8fc7 JavaScript \u52a8\u6001\u52a0\u8f7d\u7684\uff0c\u4f7f\u7528\u666e\u901a\u7684\u722c\u866b\u5e93\u65e0\u6cd5\u76f4\u63a5\u83b7\u53d6\uff0c\u8fd9\u65f6\u5c31\u53ef\u4ee5\u501f\u52a9 Selenium \u5e93\u6765\u9a71\u52a8\u6d4f\u89c8\u5668\uff0c\u6a21\u62df\u7528\u6237\u64cd\u4f5c\uff0c\u4ece\u800c\u83b7\u53d6\u5230\u5b8c\u6574\u7684\u6570\u636e\u3002_pycharm\u722c\u866b\u9700\u8981\u5b89\u88c5\u54ea\u4e9b\u5e93\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/12802.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T11:55:24+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/12802.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/12802.html\",\"name\":\"Python\u722c\u866b\uff1a\u5f00\u542f\u6570\u636e\u6293\u53d6\u7684\u5947\u5e7b\u4e4b\u65c5\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T11:55:24+00:00\",\"dateModified\":\"2025-04-18T11:55:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/12802.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/12802.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/12802.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\u722c\u866b\uff1a\u5f00\u542f\u6570\u636e\u6293\u53d6\u7684\u5947\u5e7b\u4e4b\u65c5\uff08\u4e00\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python\u722c\u866b\uff1a\u5f00\u542f\u6570\u636e\u6293\u53d6\u7684\u5947\u5e7b\u4e4b\u65c5\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/12802.html","og_locale":"zh_CN","og_type":"article","og_title":"Python\u722c\u866b\uff1a\u5f00\u542f\u6570\u636e\u6293\u53d6\u7684\u5947\u5e7b\u4e4b\u65c5\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2w\u6b21\uff0c\u70b9\u8d5e303\u6b21\uff0c\u6536\u85cf434\u6b21\u3002\u4e0d\u8fc7\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u8bed\u6cd5\u76f8\u5bf9\u590d\u6742\uff0c\u5bf9\u4e8e\u590d\u6742\u7684\u7f51\u9875\u7ed3\u6784\uff0c\u7f16\u5199\u548c\u8c03\u8bd5\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u80fd\u4f1a\u6bd4\u8f83\u56f0\u96be\uff0c\u5c31\u50cf\u662f\u5728\u4e00\u5806\u6742\u4e71\u7684\u7269\u54c1\u4e2d\u5bfb\u627e\u7279\u5b9a\u7684\u4e1c\u897f\uff0c\u9700\u8981\u82b1\u8d39\u4e00\u4e9b\u5fc3\u601d\u3002\u800c\u4e14\uff0cPython \u62e5\u6709\u5e9e\u5927\u7684\u5f00\u53d1\u8005\u793e\u533a\u548c\u4e30\u5bcc\u7684\u8d44\u6e90\uff0c\u5f53\u6211\u4eec\u5728\u5f00\u53d1\u722c\u866b\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898\u65f6\uff0c\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u5728\u793e\u533a\u4e2d\u5bfb\u6c42\u5e2e\u52a9\uff0c\u501f\u9274\u5176\u4ed6\u5f00\u53d1\u8005\u7684\u7ecf\u9a8c\u548c\u89e3\u51b3\u65b9\u6848\u3002\u5b83\u8fd8\u5177\u5907\u5f3a\u5927\u7684\u4ee3\u7801\u5206\u6790\u548c\u8c03\u8bd5\u5de5\u5177\u3002\u6bd4\u5982\uff0c\u6709\u4e9b\u7f51\u7ad9\u7684\u6570\u636e\u662f\u901a\u8fc7 JavaScript \u52a8\u6001\u52a0\u8f7d\u7684\uff0c\u4f7f\u7528\u666e\u901a\u7684\u722c\u866b\u5e93\u65e0\u6cd5\u76f4\u63a5\u83b7\u53d6\uff0c\u8fd9\u65f6\u5c31\u53ef\u4ee5\u501f\u52a9 Selenium \u5e93\u6765\u9a71\u52a8\u6d4f\u89c8\u5668\uff0c\u6a21\u62df\u7528\u6237\u64cd\u4f5c\uff0c\u4ece\u800c\u83b7\u53d6\u5230\u5b8c\u6574\u7684\u6570\u636e\u3002_pycharm\u722c\u866b\u9700\u8981\u5b89\u88c5\u54ea\u4e9b\u5e93","og_url":"https:\/\/www.wsisp.com\/helps\/12802.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T11:55:24+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/12802.html","url":"https:\/\/www.wsisp.com\/helps\/12802.html","name":"Python\u722c\u866b\uff1a\u5f00\u542f\u6570\u636e\u6293\u53d6\u7684\u5947\u5e7b\u4e4b\u65c5\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T11:55:24+00:00","dateModified":"2025-04-18T11:55:24+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/12802.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/12802.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/12802.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python\u722c\u866b\uff1a\u5f00\u542f\u6570\u636e\u6293\u53d6\u7684\u5947\u5e7b\u4e4b\u65c5\uff08\u4e00\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/12802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=12802"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/12802\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=12802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=12802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=12802"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=12802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}