﻿{"id":794,"date":"2021-01-02T08:54:35","date_gmt":"2021-01-02T00:54:35","guid":{"rendered":"https:\/\/byy3.com\/?p=794"},"modified":"2021-01-09T10:08:03","modified_gmt":"2021-01-09T02:08:03","slug":"selenium-with-tor-browser-using-python","status":"publish","type":"post","link":"https:\/\/byy3.com\/?p=794","title":{"rendered":"Selenium with Tor Browser using Python"},"content":{"rendered":"<p id=\"70bd\" class=\"hg hh fq hi b hj hk hl hm hn ho hp hq hr hs ht hu hv hw hx hy hz di dz\" data-selectable-paragraph=\"\">A Python library to automate Tor Browser with Selenium.<\/p>\n<h1 id=\"ed92\" class=\"ia ib fq av ic id ie hk if ig ih hn ii ij ik il im in io ip iq ir is it iu iv dz\" data-selectable-paragraph=\"\">Installation<\/h1>\n<h2 id=\"6e45\" class=\"iw ib fq av ic ix iy iz if ja jb jc ii jd je jf im jg jh ji iq jj jk jl iu jm dz\" data-selectable-paragraph=\"\">Step 1:<\/h2>\n<p id=\"f60f\" class=\"hg hh fq hi b hj jn hk hl hm jo hn ho hp jp hq hr hs jq ht hu hv jr hw hx hz di dz\" data-selectable-paragraph=\"\">Install Tor Browser Selenium Package.<\/p>\n<pre class=\"js jt ju jv jw jx jy jz\"><span id=\"cfae\" class=\"dz iw ib fq ka b dj kb kc s kd\" data-selectable-paragraph=\"\">pip install tbselenium<\/span><\/pre>\n<h2 id=\"b0e8\" class=\"iw ib fq av ic ix iy iz if ja jb jc ii jd je jf im jg jh ji iq jj jk jl iu jm dz\" data-selectable-paragraph=\"\">Step 2:<\/h2>\n<p id=\"bbc5\" class=\"hg hh fq hi b hj jn hk hl hm jo hn ho hp jp hq hr hs jq ht hu hv jr hw hx hz di dz\" data-selectable-paragraph=\"\">Install geckodriver in your ubuntu machine<br \/>\nYou also need to install geckodriver v0.17.0 from the\u00a0<a class=\"do ke\" href=\"https:\/\/byy3.com\/go\/?url=https:\/\/github.com\/mozilla\/geckodriver\/releases\/tag\/v0.17.0\" rel=\"noopener nofollow\" rel=\"nofollow\" >geckodriver releases page<\/a>. Make sure you install the v0.17.0 version; newer or older versions will not be compatible with the current Tor Browser series.<br \/>\nDownload the geckodriver and extract it. The driver should be move to \/usr\/local\/bin\/ directory and show the below command.<\/p>\n<pre class=\"js jt ju jv jw jx jy jz\"><span id=\"bf53\" class=\"dz iw ib fq ka b dj kb kc s kd\" data-selectable-paragraph=\"\">manivannan@manivannan-whirldatascience:~\/pythonexamle\/selenium_example$ tar -xvf geckodriver-v0.17.0-linux64.tar.gz\r\nmanivannan@manivannan-whirldatascience:~\/pythonexamle\/selenium_example$ sudo cp geckodriver \/usr\/local\/bin\/<\/span><\/pre>\n<p id=\"5c3e\" class=\"hg hh fq hi b hj kf hk hl hm kg hn ho hp kh hq hr hs ki ht hu hv kj hw hx hz di dz\" data-selectable-paragraph=\"\">Test your geckodriver installation by running the command below; it must return geckodriver 0.17.0:<\/p>\n<pre class=\"js jt ju jv jw jx jy jz\"><span id=\"3fe8\" class=\"dz iw ib fq ka b dj kb kc s kd\" data-selectable-paragraph=\"\">geckodriver --version<\/span><\/pre>\n<p id=\"2776\" class=\"hg hh fq hi b hj kf hk hl hm kg hn ho hp kh hq hr hs ki ht hu hv kj hw hx hz di dz\" data-selectable-paragraph=\"\">OUTPUT<\/p>\n<figure class=\"js jt ju jv jw kl fd fe paragraph-image\">\n<div class=\"km kn ah ko w kp\" tabindex=\"0\" role=\"button\">\n<div class=\"fd fe kk\">\n<div class=\"kv s ah kw\">\n<div class=\"kx ky s\">\n<div class=\"es kq fg ev er kr w ks kt ku\"><img loading=\"lazy\" decoding=\"async\" class=\"fg ev er kr w kz la at wq\" data-original=\"https:\/\/miro.medium.com\/max\/60\/1*NtHV7mOmCKsbjJTha8Ab7A.png?q=20\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" width=\"844\" height=\"137\" title=\"Selenium with Tor Browser using Python\u63d2\u56fe\" alt=\"Selenium with Tor Browser using Python\u63d2\u56fe\" \/><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"tu tv fg ev er kr w c\" data-original=\"https:\/\/miro.medium.com\/max\/1266\/1*NtHV7mOmCKsbjJTha8Ab7A.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" sizes=\"auto, 700px\" srcset=\"https:\/\/miro.medium.com\/max\/414\/1*NtHV7mOmCKsbjJTha8Ab7A.png 276w, https:\/\/miro.medium.com\/max\/828\/1*NtHV7mOmCKsbjJTha8Ab7A.png 552w, https:\/\/miro.medium.com\/max\/960\/1*NtHV7mOmCKsbjJTha8Ab7A.png 640w, https:\/\/miro.medium.com\/max\/1050\/1*NtHV7mOmCKsbjJTha8Ab7A.png 700w\" width=\"844\" height=\"137\" title=\"Selenium with Tor Browser using Python\u63d2\u56fe1\" alt=\"Selenium with Tor Browser using Python\u63d2\u56fe1\" \/><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/figure>\n<h2 id=\"7a3e\" class=\"iw ib fq av ic ix iy iz if ja jb jc ii jd je jf im jg jh ji iq jj jk jl iu jm dz\" data-selectable-paragraph=\"\">Step 3:<\/h2>\n<p id=\"4531\" class=\"hg hh fq hi b hj jn hk hl hm jo hn ho hp jp hq hr hs jq ht hu hv jr hw hx hz di dz\" data-selectable-paragraph=\"\">You should\u00a0<a class=\"do ke\" href=\"https:\/\/byy3.com\/go\/?url=https:\/\/www.torproject.org\/projects\/torbrowser.html.en\" rel=\"noopener nofollow\" rel=\"nofollow\" >do<span id=\"rmm\">w<\/span>nload<\/a>\u00a0and extract TBB and provide its path when you initialize TorBrowserDriver<\/p>\n<pre class=\"js jt ju jv jw jx jy jz\"><span id=\"b444\" class=\"dz iw ib fq ka b dj kb kc s kd\" data-selectable-paragraph=\"\">manivannan@manivannan-whirldatascience:~\/pythonexamle\/selenium_example$ tar -xvJf tor-browser-linux64-7.5.4_en-US.tar.xz<\/span><\/pre>\n<p id=\"c39c\" class=\"hg hh fq hi b hj kf hk hl hm kg hn ho hp kh hq hr hs ki ht hu hv kj hw hx hz di dz\" data-selectable-paragraph=\"\">The tar file is extracted and it is directory.<\/p>\n<h2 id=\"6758\" class=\"iw ib fq av ic ix iy iz if ja jb jc ii jd je jf im jg jh ji iq jj jk jl iu jm dz\" data-selectable-paragraph=\"\">Step 4:<\/h2>\n<p id=\"6b82\" class=\"hg hh fq hi b hj jn hk hl hm jo hn ho hp jp hq hr hs jq ht hu hv jr hw hx hz di dz\" data-selectable-paragraph=\"\">Install\u00a0<code class=\"kw lc ld le ka b\">xvfb<\/code>\u00a0package by running\u00a0<code class=\"kw lc ld le ka b\">apt-get install xvfb<\/code>\u00a0.<\/p>\n<pre class=\"js jt ju jv jw jx jy jz\"><span id=\"b3c0\" class=\"dz iw ib fq ka b dj kb kc s kd\" data-selectable-paragraph=\"\">manivannan@manivannan-whirldatascience:~\/pythonexamle\/selenium_example$ sudo apt-get install xvfb<\/span><\/pre>\n<p id=\"87c7\" class=\"hg hh fq hi b hj kf hk hl hm kg hn ho hp kh hq hr hs ki ht hu hv kj hw hx hz di dz\" data-selectable-paragraph=\"\">Now we started the program for take a screenshot from web browser.<br \/>\nCreate the python file and paste the below code.<\/p>\n<pre class=\"js jt ju jv jw jx jy jz\"><span id=\"6ea3\" class=\"dz iw ib fq ka b dj kb kc s kd\" data-selectable-paragraph=\"\">from tbselenium.tbdriver import TorBrowserDriver\r\nfrom os.path import dirname, join, realpath, getsize<\/span><span id=\"49b3\" class=\"dz iw ib fq ka b dj lf lg lh li lj kc s kd\" data-selectable-paragraph=\"\">out_img = join(dirname(realpath(__file__)), \"screenshot.png\")\r\nwith TorBrowserDriver(\"\/home\/manivannan\/pythonexamle\/selenium_example\/tor-browser_en-US\") as driver:\r\n driver.load_url('<a class=\"do ke\" href=\"https:\/\/byy3.com\/go\/?url=https:\/\/check.torproject.org%27\/\" rel=\"noopener nofollow\" rel=\"nofollow\" >https:\/\/check.torproject.org'<\/a>, wait_for_page_body=True)\r\n print(\"----\"*100)\r\n driver.get_screenshot_as_file(out_img)\r\n print(\"----\"*100)\r\nprint(\"Screenshot is saved as %s (%s bytes)\" % (out_img, getsize(out_img)))<\/span><\/pre>\n<p id=\"819c\" class=\"hg hh fq hi b hj kf hk hl hm kg hn ho hp kh hq hr hs ki ht hu hv kj hw hx hz di dz\" data-selectable-paragraph=\"\">\u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 -OR \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 \u2014 -<\/p>\n<p id=\"55fd\" class=\"hg hh fq hi b hj kf hk hl hm kg hn ho hp kh hq hr hs ki ht hu hv kj hw hx hz di dz\" data-selectable-paragraph=\"\">Use my github repositary link\u00a0<a class=\"do ke\" href=\"https:\/\/byy3.com\/go\/?url=https:\/\/github.com\/ManivannanMurugavel\/tor-browser-selenium\" rel=\"noopener nofollow\" rel=\"nofollow\" >here<\/a>\u00a0and i will post the advanced programs in future.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A Python library to automate Tor Browser with Selenium. [&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],"tags":[33,309,352,216,199],"class_list":["post-794","post","type-post","status-publish","format-standard","hentry","category-python","tag-python","tag-python-tor-selenium","tag-selenium","tag-tor-browser"],"_links":{"self":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/794","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=794"}],"version-history":[{"count":0,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/794\/revisions"}],"wp:attachment":[{"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}