因为Tor Browser Bundle只是Firefox的补丁版本,所以似乎应该可以使用FirefoxDriverTor浏览器.这是我到目前为止所尝试的:
String torPath = "C:\\Users\\My User\\Desktop\\Tor Browser\\Start Tor Browser.exe";
String profilePath = "C:\\Users\\My User\\Desktop\\Tor Browser\\Data\\Browser\\profile.default";
FirefoxProfile profile = new FirefoxProfile(new File(profilePath));
FirefoxBinary binary = new FirefoxBinary(new File(torPath));
FirefoxDriver driver = new FirefoxDriver(binary, profile);
driver.get("http://www.google.com");
Run Code Online (Sandbox Code Playgroud)
这会导致打开一个空白的Tor浏览器页面,并显示一条弹出消息:无法加载您的Firefox配置文件.它可能丢失或无法访问.
我知道该配置文件是有效/兼容的,因为我可以成功启动浏览器和配置文件:
binary.startProfile(profile, profilePath, ""));
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何将命令发送到以这种方式打开的浏览器.
我发现了类似的问题,但我特意寻找Java解决方案,最好在Windows上测试.
有没有办法使用geckodriver使您的 Selenium 脚本在 Python 中无法检测到?
我正在使用 Selenium 进行抓取。我们是否需要使用任何保护措施使网站无法检测到 Selenium?
我正在尝试在 Tor 上运行我的 selenium 驱动程序。请注意,该脚本在没有 Tor 的情况下已经运行且没有错误。
这是我到目前为止所做的:
1)我调用了 Tor 框架
import socks
import socket
from stem.util import term
import stem.process
SOCKS_PORT=7000
socks.setdefaultproxy(proxy_type=socks.PROXY_TYPE_SOCKS5,
addr = "127.0.0.1",
port = SOCKS_PORT)
socket.socket = socks.socksocket
# Perform DNS resolution through the socket
def getaddrinfo(*args): return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (args[0], args[1]))]
socket.getaddrinfo = getaddrinfo
def print_bootstrap_lines(line):
if "Bootstrapped " in line:
print(term.format(line, term.Color.GREEN))
tor_process = stem.process.launch_tor_with_config(
tor_cmd = "C:/Users/my-username\Desktop/Tor Browser/Browser/TorBrowser/Tor//tor.exe" ,
config = { 'SocksPort': str(SOCKS_PORT),},
init_msg_handler = print_bootstrap_lines,
)
Run Code Online (Sandbox Code Playgroud)
在调用了我理解的容器的 Tor 框架之后,我调用了 …
是否有通用的方法来检测selenium浏览器何时打开错误页面?例如,禁用您的互联网连接并执行此操作
driver.get("http://google.com")
Run Code Online (Sandbox Code Playgroud)
在Firefox中,Selenium将加载"再试一次"错误页面,其中包含"Firefox无法与www.google.com上的服务器建立连接"等文本.Selenium不会抛出任何错误.
是否有与浏览器无关的方法来检测这些案例?对于firefox(python),我可以做到
if "errorPageContainer" in [ elem.get_attribute("id") for elem in driver.find_elements_by_css_selector("body > div") ]
Run Code Online (Sandbox Code Playgroud)
但是(1)这看似计算过度(见下面的下一点)和(2)我必须为每个浏览器创建自定义代码.
如果您禁用互联网并使用htmlunit作为浏览器,您将获得一个包含以下html的页面
<html>
<head></head>
<body>Unknown host</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如何在不做的情况下检测到这一点
if driver.find_element_by_css_selector("body").text == "Unknown host"
Run Code Online (Sandbox Code Playgroud)
看起来这将是检查每一个页面加载因为通常会是一吨在正文的非常昂贵的.
如果您还知道检测负载问题类型的方法,例如没有互联网连接,无法访问的主机等,则可以获得奖励积分.
什么是硒?
当您打开Selenium的官方页面时,您首先读到的是“什么是Selenium?”中的“ Selenium automates browser”。部分。“硒的哪个部分适合我?”部分 下面提供了Selenium WebDriver和Selenium IDE之间的选择。据此,我推断出Selenium是工具的集合,该集合包括IDE,WebDriver API(语言绑定),Grid,Selenium Standalone Server,浏览器驱动程序。必须下载适当的文件才能构建项目。
什么是WebDriver?
WebDriver是一个API。它用多种语言编写,这些语言称为语言绑定。API具有控制浏览器的功能。您可以使用这些功能编写脚本来以所需的方式(测试用例)控制浏览器。
这就是我所知道的。如果我错了,请纠正我。我想从面试的角度知道这两个问题的答案。
我正在尝试连接到Tor浏览器,但收到一条错误消息,指出“ proxyConnectFailure”,我尝试了多次尝试以了解Tor浏览器的基础知识以实现连接的任何想法,但如果有什么话可以挽救生命,那一切都是徒劳的:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary(r"C:\Users\Admin\Desktop\Tor Browser\Browser\firefox.exe")
profile = FirefoxProfile(r"C:\Users\Admin\Desktop\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default")
# Configured profile settings.
proxyIP = "127.0.0.1"
proxyPort = 9150
proxy_settings = {"network.proxy.type":1,
"network.proxy.socks": proxyIP,
"network.proxy.socks_port": proxyPort,
"network.proxy.socks_remote_dns": True,
}
driver = webdriver.Firefox(firefox_binary=binary,proxy=proxy_settings)
def interactWithSite(driver):
driver.get("https://www.google.com")
driver.save_screenshot("screenshot.png")
interactWithSite(driver)
Run Code Online (Sandbox Code Playgroud) 我对此进行了研究,但得到了解决方案:
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9050)
driver = webdriver.Firefox(profile)
driver.get('http://estoeslapollaconcebol.la')
Run Code Online (Sandbox Code Playgroud)
它给出了该错误:
无法加载个人资料。配置文件目录:C:\ Users \ HPPAV1〜1 \ AppData \ Local \ Temp \ tmppcuwx3xd Firefox输出:无
当我尝试该解决方案时。
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
profile=webdriver.FirefoxProfile('C:\\Users\\HP PAV 15\\Desktop\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default\\')
binary =FirefoxBinary('C:\\Users\\HP PAV 15\\Desktop\\Tor Browser\\Browser\\firefox')
#browser = binary.launch_browser(profile)
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9150)
browser=webdriver.Firefox( binary, profile)
browser.get("http://yahoo.com")
browser.save_screenshot("/Users/admin/Pictures/screenshot.png")
browser.close()
Run Code Online (Sandbox Code Playgroud)
它给了我以下错误:
追溯(最近一次通话):文件“ C:/Python34/torfirstscript.py”,第10行,位于browser = webdriver.Firefox(二进制文件,配置文件)中文件“ C:\ Python34 \ lib \ site-packages \ selenium-2.43 .0-py3.4.egg \ …
我今天只是一个简单的问题:
我使用以下代码创建了一个新的selenium项目:
FirefoxDriver driver = new FirefoxDriver();
//ChromeDriver driver = new ChromeDriver();
//InternetExplorerDriver driver = new InternetExplorerDriver();
Run Code Online (Sandbox Code Playgroud)
Chrome和IE开箱即用,但随着Firefox的推出:
geckodriver.exe文件不存在于当前目录或PATH环境变量的目录中.该驱动程序可以从https://github.com/mozilla/geckodriver/releases下载.
为什么只有Firefox我们必须下载/配置这个驱动程序?