{"id":17,"date":"2022-08-23T13:58:12","date_gmt":"2022-08-23T05:58:12","guid":{"rendered":"https:\/\/mianka.xyz\/?p=15"},"modified":"2022-08-23T14:00:26","modified_gmt":"2022-08-23T06:00:26","slug":"linuxselenium","status":"publish","type":"post","link":"https:\/\/www.mianka.xyz\/?p=17","title":{"rendered":"\u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u4f7f\u7528selenium\u5e93"},"content":{"rendered":"<p>\u5b89\u88c5selenium\u6a21\u5757<\/p>\n<p>\u547d\u4ee4\uff1a<\/p>\n<pre class=\"prism-highlight prism-language-markup\">pip3&nbsp;install&nbsp;selenium<\/pre>\n<p><\/p>\n<p>\u5b89\u88c5chrome\u547d\u4ee4\uff1a<\/p>\n<pre class=\"prism-highlight prism-language-markup\">yum&nbsp;install&nbsp;https:\/\/dl.google.com\/linux\/direct\/google-chrome-stable_current_x86_64.rpm<\/pre>\n<p><\/p>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u662f\u4e0b\u8f7d\u5b89\u88c5\u6700\u65b0\u7684\u7a33\u5b9a\u7684chrome\u7248\u672c\uff0c\u4e0d\u662f\u56fa\u5b9a\u7684\u7248\u672c\uff0c\u6240\u4ee5\u8981\u6ce8\u610f\u4e0b\u8f7dchromedriver\u65f6\u8981\u5bf9\u5e94\u7248\u672c<\/p>\n<p><\/p>\n<p>\u67e5\u770b\u7248\u672c<\/p>\n<pre class=\"prism-highlight prism-language-markup\">google-chrome&nbsp;--version<\/pre>\n<p><\/p>\n<p>\u6211\u662f\u5728\u672c\u5730win10\u7cfb\u7edf\u53c8\u4e0b\u4e86\u4e00\u904d\uff0c\u89e3\u538b\u53ef\u4ee5\u770b\u5230chrome\u7248\u672c\u662f86<\/p>\n<p><\/p>\n<p>\u6ce8\uff1a\u5982\u679c\u8fd0\u884c\u7a0b\u5e8f\u51fa\u9519\uff1aCannot find Chrome binary\uff0c\u5c31\u662f\u6ca1\u6709\u5b89\u88c5chrome<\/p>\n<p><\/p>\n<p>\u5b89\u88c5\u4f9d\u8d56\u5e93<\/p>\n<p>\u547d\u4ee4\uff1a<\/p>\n<pre class=\"prism-highlight prism-language-markup\">yum&nbsp;install&nbsp;pango.x86_64&nbsp;libXcomposite.x86_64&nbsp;libXcursor.x86_64&nbsp;libXdamage.x86_64&nbsp;libXext.x86_64&nbsp;libXi.x86_64&nbsp;libXtst.x86_64&nbsp;cups-libs.x86_64&nbsp;libXScrnSaver.x86_64&nbsp;libXrandr.x86_64&nbsp;GConf2.x86_64&nbsp;alsa-lib.x86_64&nbsp;atk.x86_64&nbsp;gtk3.x86_64&nbsp;-y<\/pre>\n<p><\/p>\n<p>\u6ce8\uff1a\u5982\u679c\u6ca1\u6709\u5b89\u88c5\u4f9d\u8d56\u5e93\u4f1a\u62a5\u9519\uff1aerror while loading shared libraries: libX11.so.6:<\/p>\n<p><\/p>\n<p>\u5b89\u88c5chromedriver\uff08\u9a71\u52a8\u7a0b\u5e8f\uff09<\/p>\n<p><\/p>\n<p>\u4e0b\u8f7d\u94fe\u63a5\u5982\u4e0b\uff1a\u70b9\u6211\u4e0b\u8f7d\uff0c\u4e00\u5b9a\u8981\u627e\u5230\u4e0e\u4e0a\u9762chrome\u7248\u672c\u76f8\u5e94\u7684\u7248\u672c\uff0c\u8fd9\u91cc\u4e0b\u8f7d\u548c\u4e0a\u9762\u5bf9\u5e94\u768486\u7248\u672c<\/p>\n<p><\/p>\n<p>\u53ef\u4ee5windows\u4e0b\u8f7d\u540e\u7136\u540e\u4f20\u5230\u670d\u52a1\u5668\u4e0a\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528wget\u547d\u4ee4\u4e0b\u8f7d<\/p>\n<p><\/p>\n<p>\u547d\u4ee4\uff1a<\/p>\n<pre class=\"prism-highlight prism-language-markup\">wget&nbsp;http:\/\/chromedriver.storage.googleapis.com\/index.html?path=86.0.4240.22\/<\/pre>\n<p><\/p>\n<p>\u7136\u540e\u7ed9chromedriver \u6587\u4ef6\u8d4b\u4e88\u53ef\u6267\u884c\u6743\u9650<\/p>\n<p><\/p>\n<p>\u547d\u4ee4\uff1a<\/p>\n<pre class=\"prism-highlight prism-language-markup\">chmod&nbsp;777&nbsp;chromedriver<\/pre>\n<p><\/p>\n<p>\u7136\u540e\u653e\u5230\u73af\u5883\u53d8\u91cfPATH\u8def\u5f84\u4e2d<\/p>\n<p><\/p>\n<p>\u547d\u4ee4\uff1a<\/p>\n<pre class=\"prism-highlight prism-language-markup\">cp&nbsp;chromedriver&nbsp;\/usr\/bin\/<\/pre>\n<p><\/p>\n<p>\u53ef\u4ee5\u67e5\u770bchromedriver\u7684\u7248\u672c\u53f7<\/p>\n<p><\/p>\n<p>\u547d\u4ee4\uff1a<\/p>\n<pre class=\"prism-highlight prism-language-markup\">chromedriver&nbsp;--version<\/pre>\n<p><\/p>\n<p>selenium\u4ee3\u7801\u6d4b\u8bd5<\/p>\n<p><\/p>\n<p>\u5728\u670d\u52a1\u5668\u4e0a\u65b0\u5efa\u4e00\u4e2apython\u6587\u4ef6\uff0c\u5199\u5165\u4ee5\u4e0b\u4ee3\u7801<\/p>\n<p><\/p>\n<pre class=\"prism-highlight prism-language-python\">#!\/usr\/bin\/python3\n#coding:utf-8\nfrom&nbsp;selenium&nbsp;import&nbsp;webdriver\nch_options&nbsp;=&nbsp;webdriver.ChromeOptions()\n#\u4e3aChrome\u914d\u7f6e\u65e0\u5934\u6a21\u5f0f\nch_options.add_argument(&quot;--headless&quot;)&nbsp;&nbsp;\nch_options.add_argument(&#39;--no-sandbox&#39;)\nch_options.add_argument(&#39;--disable-gpu&#39;)\nch_options.add_argument(&#39;--disable-dev-shm-usage&#39;)\n#&nbsp;\u5728\u542f\u52a8\u6d4f\u89c8\u5668\u65f6\u52a0\u5165\u914d\u7f6e\ndr&nbsp;=&nbsp;webdriver.Chrome(options=ch_options)\n#\u8fd9\u662f\u6d4b\u8bd5\u7f51\u7ad9\nurl&nbsp;=&nbsp;&quot;https:\/\/www.baidu.com&quot;\ndr.get(url)\n#\u6253\u5370\u6e90\u7801\nprint(dr.page_source)<\/pre>\n<p><\/p>\n<p>\u7136\u540epython\u6267\u884c\u8fd9\u4e2apy\u6587\u4ef6\uff0c\u7ed3\u679c\u6253\u5370\u51fa\u4e86\u6e90\u7801\uff0c\u5373selenium\u6a21\u5757\u73af\u5883\u914d\u7f6e\u6210\u529f\u3002<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88c5selenium\u6a21\u5757<\/p>\n<p>\u547d\u4ee4\uff1a<\/p>\n<pre class=\"prism-highlight prism-language-markup\">pip3&nbsp;install&nbsp;selenium<\/pre>\n<p><\/p>\n<p>\u5b89\u88c5chrome\u547d\u4ee4\uff1a<\/p>\n<pre class=\"prism-highlight prism-language-markup\">yum&nbsp;install&nbsp;https:\/\/dl.google.com\/linux\/direct\/google-chrome-stable_current_x86_64.rpm<\/pre>\n<p><!--autointro--><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-17","post","type-post","status-publish","format-standard","hentry","category-pythonbiji"],"_links":{"self":[{"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/posts\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17"}],"version-history":[{"count":0,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/posts\/17\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}