selenium control tor browser

(Technical purely their own blind study, other losers nothing to do with me!) *

About tor
tor is a browser, Firefox is the kernel of the ordinary, but they are not the same and, most important function is tor can achieve multiple ip conversion and dynamic (I will not dim explained). There is a hidden and known function ------- visit the legendary network of an

Sock5 an access network protocol requires conversion into http how I will not say (my brother gave me) and then we just say today's main event selenium control tor browser.

Because the browser kernel is tor Firefox and Firefox start method as it is, but because the tor browser has its own firefox.exe
so we just need to set the startup boot file path to the firefox.exe tor of.

Thinking that it would be finished? no! Such a simple start firefox.exe will appear tor failed to start. It found that the normal parameters and Firefox profiles of firefox.exe tor's in my repeated testing is not the same. Therefore, we need to send us the path of the configuration file of selenium.

    topath = "C:\\Users\\zbx\\Desktop\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default"
    #这是配置文件的路径
    path = 'C:\\Users\\zbx\\Desktop\\Tor Browser\\firefox.exe'
    #这是启动驱动的路径

But I think this will finish when I found. This can really start tor but can not access any web page. It has been displayed agency problems. I also tested the proxy is not the problem that is most Niubi place ----- tor tor loop

But I have studied for a long time did not find the ring is how his generation (Bena) and then another way to call it directly. Let him generate loop. We let the browser is in the loop on ok

Act One:

	topath = "C:\\Users\\zbx\\Desktop\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default"
    path = 'C:\\Users\\zbx\\Desktop\\Tor Browser\\firefox.exe'
    profile = webdriver.firefox.firefox_profile.FirefoxProfile(topath)
    profile1=webdriver.FirefoxProfile()
    profile.set_preference("webdriver.firefox.bin", path)
    profile=webdriver.FirefoxOptions()
    profile.set_preference("binary", path)
    profile.set_preference("profile", topath)
    profile.set_preference('network.proxy.type', 1)
    profile.set_preference('network.proxy.socks', 'ip(自己写代理)')
    profile.set_preference('network.proxy.socks_port', 9150)
    driver=webdriver.Firefox(options=profile)
    
    

So we started but how we let him tor tor in the loop Nom:
My approach is to start cmd browser tor tor he will start a loop

os.system(
       C:\\Users\\zbx\\Desktop\\Tor Browser\\firefox.exe ' https://login.baidu.com')

So we use selenium tor the control

Method two:
with reference to very old versions of code change to the java
run.py

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.common.exceptions import NoSuchElementException
from subprocess import Popen
from os import getcwd
from time import sleep
import time
def setup_tor(binary, delay=False):
    global driver
    Popen('initialize.bat', cwd=getcwd())
    if delay:
        sleep(delay)
    driver = webdriver.Firefox(firefox_binary=binary)
def check_tor():
   #l里面是你selenium的操作
if __name__ == '__main__':
    binary = FirefoxBinary('{}\\Browser\\firefox.exe'.format(open('path.txt', 'r').read().strip('\n')))
    setup_tor(binary)
    check_tor()

path.txt

C:\Users\zbx\Desktop\Tor Browser

initialize.bat

set /p binary=<path.txt
"%binary%\Browser\firefox.exe"

Well, today to analyze here. (Pure technical discussions, the other nothing to do with me)
I love the motherland
prosperous, democratic, civilized, harmonious, freedom, equality, justice, rule of law, patriotic, dedicated, honest, friendly.

Released six original articles · won praise 32 · views 1533

Guess you like

Origin blog.csdn.net/qq_41927995/article/details/100019922