{"id":1397,"date":"2022-10-16T16:14:31","date_gmt":"2022-10-16T08:14:31","guid":{"rendered":"http:\/\/blog.xtaa.cn\/?p=1397"},"modified":"2023-11-15T20:40:18","modified_gmt":"2023-11-15T12:40:18","slug":"%e4%bd%bf%e7%94%a8selenium%e8%87%aa%e5%8a%a8%e7%99%bb%e5%bd%95","status":"publish","type":"post","link":"http:\/\/blog.xtaa.cn\/index.php\/2022\/10\/16\/%e4%bd%bf%e7%94%a8selenium%e8%87%aa%e5%8a%a8%e7%99%bb%e5%bd%95\/","title":{"rendered":"\u4f7f\u7528selenium"},"content":{"rendered":"\n<p>\u4e00\u3001\u73af\u5883\u642d\u5efa<br>\uff081\uff09\u5b89\u88c5selenium\u5e93:<br>\u5982\u679c\u5b89\u88c5\u4e0d\u4e0a\u5c31\u4e0a\u56fd\u5185\u6e90<\/p>\n\n\n\n<p>pip install selenium -i http:\/\/pypi.douban.com\/simple &#8211;trusted-host pypi.douban.com<\/p>\n\n\n\n<p>\uff082\uff09\u4e0b\u8f7dChrome\u9a71\u52a8\uff1a<br>chromedriver\u7684\u4e0b\u8f7d\u5730\u5740http:\/\/chromedriver.storage.googleapis.com\/index.html<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \u9700\u8981\u6ce8\u610f\u7684\u662f\u8fd9\u91cc\u6709\u5f88\u591a\u79cd\u7248\u672c\uff0c\u8fd9\u91cc\u9700\u8981\u4e0b\u8f7d\u548c\u4f60\u6d4f\u89c8\u5668\u7248\u672c\u6700\u63a5\u8fd1\u7684\u4e00\u4e2a\u3002\u6ce8\u610f\u662f\u6700\u63a5            \u8fd1\uff0c\u6253\u5f00\u6d4f\u89c8\u5668,\u5728\u5730\u5740\u680f\u8f93\u5165chrome:\/\/version\/\u4fbf\u53ef\u4ee5\u67e5\u770b\u5230\u8c37\u6b4c\u5f53\u524d\u7684\u7248\u672c\u53f7\n\n    \u89e3\u538b\u4f1a\u5f97\u5230\u4e00\u4e2achromedriver.exe(\u540d\u5b57\u4e0d\u540c\u5c31\u5fc5\u6210\u8fd9\u4e2a)\u6587\u4ef6\u3002\u5982\u679c\u6ca1\u6709\u6700\u65b0\u7248\u672c\u53ef\u5230\u4ee5\u4e0b\u5730\u5740\u67e5\u770b\n<a href=\"https:\/\/googlechromelabs.github.io\/chrome-for-testing\/\">https:\/\/googlechromelabs.github.io\/chrome-for-testing\/<\/a><\/code><\/pre>\n\n\n\n<p>\u56e0\u4e3achrome\u4f1a\u81ea\u52a8\u66f4\u65b0\uff0c\u6240\u4ee5\u8981<strong>\u5728\u670d\u52a1\u6216\u8005\u8ba1\u5212\u4efb\u52a1\u7ba1\u7406(\u63a7\u5236\u9762\u677f-\u7cfb\u7edf\u548c\u5b89\u5168-windows\u5de5\u5177-\u8ba1\u5212\u4efb\u52a1)\u91cc\u628a\u81ea\u52a8\u66f4\u65b0\u7981\u7528<\/strong><\/p>\n\n\n\n<p>\uff083\uff09\u5c06Chromedriver\u52a0\u5165\u5230path:<br><\/p>\n\n\n\n<p>1.\u684c\u9762\u53f3\u51fb\u8c37\u6b4c\u6d4f\u89c8\u5668&#8211;&gt;\u6253\u5f00\u6587\u4ef6\u6240\u5728\u4f4d\u7f6e\uff0c\u5c06\u521a\u89e3\u538b\u7684.exe\u6587\u4ef6\u590d\u5236\u4e00\u4efd\u5230\u6b64\u8def\u5f84\u4e0b<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li>\u5c06\u521a\u521a\u89e3\u538b\u7684.exe\u6587\u4ef6\u590d\u5236\u4e00\u4efd\uff0c\u653e\u5165python\u6839\u76ee\u5f55\u4e2d <code>\u81f3\u4e8e\u5982\u4f55\u67e5\u770b\u81ea\u5df1\u7684python\u6839\u76ee\u5f55\uff0c\u53ef\u5728cmd\u4e0b\u8fdbpython\uff0c\u518d\u8f93\u5165 where python\u53ef\u5f97\u76ee\u5f55<\/code><\/li>\n\n\n\n<li>\u5c06.exe\u6587\u4ef6\u518d\u590d\u5236\u5e76\u653e\u5230\u5f53\u524d\u5de5\u7a0b\u6587\u4ef6\u540c\u6587\u4ef6\u5939\u4e0b<\/li>\n<\/ol>\n\n\n\n<p><\/p>\n\n\n\n<p>\u53ef\u4ee5\u6d4b\u8bd5\u4e0b\u770b\u662f\u5426\u53ef\u4ee5\uff0cpython\u7f16\u8bd1\u5668\uff0c\u7f16\u5199\u5982\u4e0b\u4ee3\u7801\uff0c\u8fd0\u884c\u5982\u679c\u51fa\u73b0\u7a97\u53e3\uff0c\u63d0\u793a\u6b63\u53d7\u6d4b\u8bd5\u8f6f\u4ef6\u63a7\u5236\uff0c\u8bf4\u660e\u53ef\u4ee5\u4e86\uff0c\uff08\u53cd\u5e94\u6162\uff0c\u7b2c\u4e00\u6b21\u53ef\u80fd\u89811\u5206\u591a\u949f\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from selenium import webdriver\nfrom time import sleep\n\ndriver = webdriver.Chrome()\ndriver.get(\"http:\/\/www.baidu.com\")\nsleep(2)\ndriver.quit()\n<\/code><\/pre>\n\n\n\n<p>\u5230\u6b64\u5904\u53ef\u80fd\u5df2\u53ef\u4ee5\u4e86\uff0c\u5982\u679c\u4e0d\u884c\u8fdb\u884c4\u548c5\u6b65\uff0c<\/p>\n\n\n\n<p>\uff084\uff09\u5c06\u6d4f\u89c8\u5668\u73af\u5883\u53d8\u91cf\u6dfb\u52a0\u5230path\uff1a<br>\u6253\u5f00\u5f00\u59cb\u83dc\u5355-&gt;\u6211\u7684\u7535\u8111\uff08\u6216\u8ba1\u7b97\u673a\uff09-&gt;\u7cfb\u7edf\u5c5e\u6027-&gt;\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e-&gt;\u73af\u5883\u53d8\u91cf\uff0c\u7f16\u8f91\u7528\u6237\u53d8\u91cf\u91cc\u7684path\uff0c \u5728\u6700\u540e\u9762\u6dfb\u52a0;C:\\Program Files (x86)\\Google\\Chrome\\Application\\ \u6216\u8005\u5728\u6700\u524d\u9762\u6dfb\u52a0C:\\Program Files (x86)\\Google\\Chrome\\Application\\ \u4fee\u6539\u5b8c\u4e4b\u540e\u70b9\u51fb\u786e\u5b9a\u6309\u94ae\u4fdd\u5b58\u914d\u7f6e\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u51fa\u9519\uff0c\u5219\uff1a<\/p>\n\n\n\n<p>\u5c06chromedriver.exe\u6587\u4ef6\u653e\u5165python\u7684scripts\u76ee\u5f55\uff0c\u5e76\u5c06\u8be5scripts\u76ee\u5f55\u6dfb\u52a0\u5230\u7cfb\u7edfpath\u53d8\u91cf\u4e2d\uff1b<br>3\u3001\u627e\u5230Google Chrome\u5b89\u88c5\u76ee\u5f55\uff0c\u4e00\u822c\u5728C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\Application\\Google Chrome.exe\uff0c\u5c06Google Chrome.exe\u590d\u5236\u4e00\u4e2a\u51fa\u6765\uff0c\u5e76\u91cd\u547d\u540d\u4e3achrome.exe\uff0c\u5e76\u5c06\u76ee\u5f55C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\Application\\\u6dfb\u52a0\u5230\u7cfb\u7edfpath\u53d8\u91cf\u4e2d<\/p>\n\n\n\n<p>\u6ce8\u610f\u4f60\u7684\u8def\u5f84\u4e0d\u4e00\u5b9a\u548c\u4ed6\u76f8\u540c\uff0c\u8fd9\u4e2a\u5c31\u662f\u53f3\u51fb\u8c37\u6b4c\u6d4f\u89c8\u5668\u56fe\u6807\u7684\u8def\u5f84,\u590d\u5236\u4e0b\u6765\u5c31\u597d\u4e86<\/p>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u73af\u5883\u642d\u5efa\uff081\uff09\u5b89\u88c5selenium\u5e93:\u5982\u679c\u5b89\u88c5\u4e0d\u4e0a\u5c31\u4e0a\u56fd\u5185\u6e90 pip install selenium &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-1397","post","type-post","status-publish","format-standard","hentry","category-10"],"_links":{"self":[{"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/posts\/1397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1397"}],"version-history":[{"count":8,"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/posts\/1397\/revisions"}],"predecessor-version":[{"id":1900,"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/posts\/1397\/revisions\/1900"}],"wp:attachment":[{"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1397"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xtaa.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}