First implementation
parent
26511e6a4f
commit
fad8337541
2
LICENSE
2
LICENSE
|
|
@ -219,7 +219,7 @@ If you develop a new program, and you want it to be of the greatest possible use
|
|||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
grattoir
|
||||
gerold
|
||||
Copyright (C) 2024 mmalter
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
from selenium.webdriver import firefox
|
||||
from fake_useragent import UserAgent
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
|
||||
def tor_profile():
|
||||
tor_firefox_path = str(Path("~/.tor project/firefox").expanduser())
|
||||
ini_path = tor_firefox_path + "/profiles.ini"
|
||||
with open(ini_path) as ini:
|
||||
for line in ini:
|
||||
if "Path=" in line:
|
||||
return tor_firefox_path + '/' + line.split('=')[1][:-1]
|
||||
|
||||
|
||||
def tor_browser_binary_path():
|
||||
for pe in os.environ["PATH"].split(os.pathsep):
|
||||
checkname = os.path.join(pe, "tor-browser")
|
||||
if os.access(checkname, os.X_OK) and not os.path.isdir(checkname):
|
||||
return checkname
|
||||
return None
|
||||
|
||||
|
||||
class Grattoir(object):
|
||||
def __init__(self):
|
||||
self._driver = None
|
||||
|
||||
def __enter__(self):
|
||||
p_path = tor_profile()
|
||||
profile = firefox.firefox_profile.FirefoxProfile(profile_directory=p_path)
|
||||
b_path = tor_browser_binary_path()
|
||||
binary = firefox.firefox_binary.FirefoxBinary(firefox_path=b_path)
|
||||
o = firefox.options.Options()
|
||||
o.profile = profile
|
||||
o.binary = binary
|
||||
self._driver = firefox.webdriver.WebDriver(options=o)
|
||||
return self._driver
|
||||
|
||||
def __exit__(self, exc_type, exc_value, exc_tb):
|
||||
self._driver.quit()
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
[tool.poetry]
|
||||
name = "grattoir"
|
||||
version = "0.1.0"
|
||||
license = "AGPL-3.0-or-later"
|
||||
description = "A selenium webdriver using Tor IPs"
|
||||
authors = ["Michaeël Malter <dev@michaelmalter.fr>"]
|
||||
readme = "README.md"
|
||||
packages = [{include = "grattoir"}]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.11.9"
|
||||
selenium = "^4.23.1"
|
||||
fake-useragent = "^1.5.1"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
Loading…
Reference in New Issue