﻿{"id":746,"date":"2020-12-15T01:07:16","date_gmt":"2020-12-14T17:07:16","guid":{"rendered":"https:\/\/byy3.com\/?p=746"},"modified":"2021-02-08T19:00:56","modified_gmt":"2021-02-08T11:00:56","slug":"linux%e7%8e%af%e5%a2%83%e4%bd%bf%e7%94%a8python%e8%b0%83%e7%94%a8tor%e6%b5%8f%e8%a7%88%e5%99%a8%e9%9a%8f%e6%9c%ba%e6%b5%8f%e8%a7%88%e5%99%a8%e7%bd%91%e9%a1%b5","status":"publish","type":"post","link":"https:\/\/byy3.com\/?p=746","title":{"rendered":"linux\u73af\u5883\u4f7f\u7528python\u8c03\u7528tor\u6d4f\u89c8\u5668\u968f\u673a\u6d4f\u89c8\u5668\u7f51\u9875"},"content":{"rendered":"<p>linux\u73af\u5883\u4f7f\u7528python\u7684selenium\u6a21\u5757\u8c03\u7528tor\u6d4f\u89c8\u5668\u968f\u673a\u6d4f\u89c8\u5668\u7f51\u9875<br \/>\n\u6e90\u7801\u53c2\u8003https:\/\/github.com\/lvwuwei\/tor-browser-selenium<\/p>\n<p>\u9996\u5148\u5728Linux\u684c\u9762\u73af\u5883\u4e0b\u5b89\u88c5tor\u6d4f\u89c8\u5668<br \/>\nsudo apt install torbrowser-launcher<\/p>\n<p>***\u5b89\u88c5\u597d\u540e\u8bb0\u5f97\u70b9\u51fb\u83dc\u5355\u641c\u7d22tor\u7136\u540e\u70b9\u51fb\u8fd0\u884c\u4f1a\u4e0b\u8f7d\u521d\u59cb\u5316tor\u6d4f\u89c8\u5668<br \/>\n\uff08\u5982\u679c\u662froot\u7528\u6237\u4f1a\u5f39\u51fa\u65e0\u6cd5\u5728root\u7528\u6237\u4e0b\u8fd0\u884ctor\u8bf7\u53c2\u8003https:\/\/byy3.com\/739.html\uff09linux\u4f7f\u7528<a href=\"https:\/\/byy3.com\/739.html\">root\u8fd0\u884ctor\u6d4f\u89c8\u5668<\/a><br \/>\n\u5927\u6982\u662f94-97\u884c\uff01<\/p>\n<p>***\u8bbe\u7f6e\u597d\u540e\uff0c\u518d\u6b21\u83dc\u5355\u641c\u7d22tor\u70b9\u51fb\u8fd0\u884c\uff0c\u521d\u59cb\u5316\u4ee3\u7406\u8bbe\u7f6e<\/p>\n<p>\u7136\u540e\u4f7f\u7528python3 <a href=\"https:\/\/byy3.com\/81.html\">pip3\u5b89\u88c5<\/a>tbselenium <strong>\u547d\u4ee4<\/strong>pip3 install tbselenium<br \/>\n\uff08\u6ca1\u6709pip3\u53c2\u8003pip3\u642d\u914dpython3\u7684\u73af\u5883\u4f7f\u7528https:\/\/byy3.com\/81.html\uff09<\/p>\n<p>\u7136\u540e \u4e0b\u8f7dgeckodriver\u6d4f\u89c8\u5668\u6838\u5fc3\u9a71\u52a8<br \/>\nwget <a href=\"https:\/\/byy3.com\/go\/?url=https:\/\/github.com\/mozilla\/geckodriver\/releases\/download\/v0.28.0\/geckodriver-v0.28.0-linux64.tar.gz\" rel=\"nofollow\" ><a href=\"https:\/\/byy3.com\/go\/?url=https:\/\/github.com\/mozilla\/geckodriver\/releases\/download\/v0.28.0\/geckodriver-v0.28.0-linux64.tar.gz\" rel=\"nofollow\" >https:\/\/github.com\/mozilla\/geckodriver\/releases\/download\/v0.28.0\/geckodriver-v0.28.0-linux64.tar.gz<\/a><\/a><br \/>\n\u89e3\u538b\u7f29tar -xvf geckodriver-v0.17.0-linux64.tar.gz \u5f97\u5230geckodriver\u6587\u4ef6\u5939<br \/>\n\u590d\u5236\u5230\u7528\u6237\u76ee\u5f55\u6587\u4ef6\u5939\u4e0bsudo cp geckodriver \/usr\/local\/bin\/<br \/>\n\u4f7f\u7528\u547d\u4ee4\u6d4b\u8bd5\u6d4f\u89c8\u5668\u73af\u5883\u5b89\u88c5\u597d\u4e86\u6ca1\u6709geckodriver --version<br \/>\n\u5f97\u5230\u7248\u672cgeckodriver 0.28.0 \u5c31\u597d\u4e86<\/p>\n<p>Install xvfb package by running apt-get install xvfb .<br \/>\n\u547d\u4ee4$ sudo apt-get install xvfb<\/p>\n<p>\u518d\u6b21\u5728\u641c\u7d22\u680f\u4e2d\u641c\u7d22tor\u5e76\u4e14\u6253\u5f00tor\u6d4f\u89c8\u5668\u4f1a\u521d\u59cb\u5316<br \/>\n<strong>\u5f00\u542f\u670d\u52a1sudo service tor restar<\/strong>t<\/p>\n<pre>\u7136\u540e\u65b0\u5efator.py \u6d4b\u8bd5\u7a0b\u5e8f\nfrom tbselenium.tbdriver import TorBrowserDriver\nfrom os.path import dirname, join, realpath, getsize\nout_img = join(dirname(realpath(__file__)), \"screenshot.png\")\nwith TorBrowserDriver(\"\/root\/.local\/share\/torbrowser\/tbb\/x86_64\/tor-browser_en-US\/\") as driver:\ndriver.load_url('https:\/\/check.torproject.org', wait_for_page_body=True)\nprint(\"----\"*300)\ndriver.get_screenshot_as_file(out_img)\nprint(\"----\"*300)\nprint(\"Screenshot is saved as %s (%s bytes)\" % (out_img, getsize(out_img)))\n#\u672a\u5b8c\u6210 \u52a0\u5165\u5173\u95ed\u6d4f\u89c8\u5668\u548c\u70b9\u51fbxpath\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-747\" data-original=\"https:\/\/byy3.com\/wp-content\/uploads\/2020\/12\/2020121417070228.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" width=\"1000\" height=\"500\" title=\"linux\u73af\u5883\u4f7f\u7528python\u8c03\u7528tor\u6d4f\u89c8\u5668\u968f\u673a\u6d4f\u89c8\u5668\u7f51\u9875\u63d2\u56fe\" alt=\"linux\u73af\u5883\u4f7f\u7528python\u8c03\u7528tor\u6d4f\u89c8\u5668\u968f\u673a\u6d4f\u89c8\u5668\u7f51\u9875\u63d2\u56fe\" \/><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>linux\u73af\u5883\u4f7f\u7528python\u7684selenium\u6a21\u5757\u8c03\u7528tor\u6d4f\u89c8\u5668\u968f\u673a\u6d4f\u89c8\u5668\u7f51\u9875 \u6e90\u7801\u53c2\u8003https:\/\/g [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,21],"tags":[471,214,352,215,216,217,199,201],"class_list":["post-746","post","type-post","status-publish","format-standard","hentry","category-python","category-script","tag-js-bat","tag-python-tor","tag-python","tag-pythontor","tag-selenium","tag-tbselenium","tag-tor-browser","tag-tor"],"_links":{"self":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=746"}],"version-history":[{"count":0,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/746\/revisions"}],"wp:attachment":[{"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}