(Technology is just my own blind research, nothing else has to do with me!) *
Introduction to tor
Tor is a browser, and its core is Firefox, but it's different from the normal one. The most important function of tor is that it can realize multiple conversion and dynamic of ip. There is also a hidden and well-known function - - - visiting the legendary an network
The sock5 protocol for access to an network needs to be converted into http, so I won't say (my eldest brother gave it to me) and then we'll just talk about today's highlight, selenium control tor browser.
Because the core of tor browser is Firefox browser, the method of booting is the same as Firefox browser, but because tor browser has its own firefox.exe
So we just need to set the startup file to the startup path of firefox.exe of tor.
Think it's over? no! firefox.exe started in this way alone will show that tor failed to start. In my repeated tests, I found that the parameters of tor firefox. exe configuration file are different from those of normal Firefox. So we need to pass the path of the configuration file to our selenium.
topath = "C:\\Users\\zbx\\Desktop\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default" #This is the path to the configuration file path = 'C:\\Users\\zbx\\Desktop\\Tor Browser\\firefox.exe' #This is the boot-driven path
But I think when that's done, I found out. This does start tor but does not allow access to any web pages. The proxy problem is always displayed. I've tested proxy again. No problem. That's the most powerful place in tor - --- tor loop.
But I studied it for a long time and didn't find out how his ring was generated. Then I to ok a different path and called it directly. Let him make his own loop. We're putting browsers in this loop.
Law 1:
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(Write your own agent)') profile.set_preference('network.proxy.socks_port', 9150) driver=webdriver.Firefox(options=profile)
So we started tor, but how do we get him in the tor loop?
My solution is that cmd starts the tor browser and he starts a tor loop
os.system( C:\\Users\\zbx\\Desktop\\Tor Browser\\firefox.exe ' https://login.baidu.com')
So we use selenium to control tor s.
Law II:
It's based on a very old version of 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 It's your selenium operation. 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, that's all for today's analysis. (Pure technical discussion, nothing else to do with me)
I love my motherland
Richness, democracy, civilization, harmony, freedom, equality, justice, rule of law, patriotism, dedication, integrity and friendliness.