我需要确认If Stem是否可用于启动暴露127.0.0.1:port的Tor进程,然后在selenium脚本上使用它作为代理(SOCKS).
我在Windows上使用Python 3.4.2,Stem 1.3.0和Tor(tor-win32-tor-0.2.5.10专家包).
这段代码适用于标准的SOCKS代理.
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
profile = 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', 9000)
driver = webdriver.Firefox(profile)
driver.implicitly_wait(30)
driver.get('http://www.reddit.com')
Run Code Online (Sandbox Code Playgroud)
但我无法让它与Tor合作作为我的代理.我试图创建一个Tor进程,并创建它.但我真的不知道它是否正常工作.我不会在我的错误中得到错误tor_error_log.txt
# File: stem_process.py
import stem.process
import stem
stem.process.launch_tor_with_config(
config = {
'SocksPort': '9000',
'ControlPort': '9051',
'ExitNodes': '{us}',
'Log': [
'NOTICE stdout',
'ERR file c:\\tor-win32-tor-0.2.5.10\\Tor\\tor_error_log.txt',
],
},
tor_cmd = 'C:\\tor-win32-tor-0.2.5.10\\Tor\\tor.exe',
)
Run Code Online (Sandbox Code Playgroud)
然后我尝试了两种方法来创建连接或进行身份验证.第一个是使用with和stem.control.controller.而第二个在较低的水平与stem.socket和stem.connection
第一个:
# File: stem_test1.py
from stem.control import Controller
with Controller.from_port(address='127.0.0.1', port=9051) as …Run Code Online (Sandbox Code Playgroud) 实际上我对弹簧代理的行为感到困惑.我想我知道j2ee,cglib和aspectj的代理机制之间的主要区别.我在配置类中启用了aspectj自动代理,并且aspectj包含在类路径中.
我的配置
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class ApplicationConfiguration {
...
}
Run Code Online (Sandbox Code Playgroud)
AspectJ依赖
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.5</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
通过使用这个简单的设置,我假设bean注入按预期工作.但相反,我的应用程序会生成IllegalArgumentException带有"无法将[...]字段[...]设置为com.sun.proxy.$ Proxy30"的消息.这意味着Spring使用j2ee代理服务,即使启用了aspectj代理也是如此.
最后我发现我的服务上的接口导致了这种行为.当我的服务实现任何接口时,似乎spring决定使用j2ee代理.如果我删除它们,它的工作原理.
失败:
@Service
@Validated
public class MyService implements Interface1, Interface2 {
@override
public void methodFromInterface1() {
}
@override
public void methodFromInterface2() {
}
public void serviceMethod() {
}
}
Run Code Online (Sandbox Code Playgroud)
好:
@Service
@Validated
public class MyService {
public void methodFromInterface1() {
}
public void methodFromInterface2() {
}
public void serviceMethod() {
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经明白j2ee代理需要接口.但对我来说这是新的,cglib/aspectj代理不适用于实现接口的bean.
有没有办法......
...强制春天不使用j2ee代理?
...强制spring使用cglib/aspectj代理(即使对于有接口的类)?
这是春天的错误或期望的行为吗?
编辑 …
HTTP/2禁止特定于连接的标头字段.不得出现以下标题字段:"连接","保持活动","代理连接","传输编码"和"升级".此外,"TE"标题字段不得包含"预告片"以外的任何值.
我想问的是,由于HTTP/2禁止Transfer-Encoding标头,所以HTTP/2代理如何处理标头Tranfer-Encoding:chunked?
如果代理总是将整个chunked请求缓存在内存中并添加Content-Length头,那么发送到HTTP/2服务器/客户端?
我想通过hotmail smtp使用python脚本发送电子邮件,但我已连接到代理服务器.
有我的代码,当它直接连接到互联网时它工作但是它连接到他不工作的代理服务器.
import smtplib
smtpserver = 'smtp.live.com'
AUTHREQUIRED = 1
smtpuser = 'example@hotmail.fr'
smtppass = 'mypassword'
RECIPIENTS = 'mailto@gmail.com'
SENDER = 'example@hotmail.fr'
mssg = "test message"
s = mssg
server = smtplib.SMTP(smtpserver,587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(smtpuser,smtppass)
server.set_debuglevel(1)
server.sendmail(SENDER, [RECIPIENTS], s)
server.quit()
Run Code Online (Sandbox Code Playgroud) @scope annotaion的proxyMode和上下文组件扫描的scopedProxy之间是否有任何区别?
我知道后者将在上下文组件扫描下的指定包值中的所有类中启用代理.
我只是想知道两者之间是否存在任何功能差异,或者仅仅是前者(@scope的代理模式用于在特定bean上启用代理)
我试图设置browsermob在我的硒项目中工作。我一直在寻找一种使用ChromeOptions设置代理的方法,但是所有消息来源都告诉我在所有其他示例中都使用ChromeOptions,然后在实例化新的ChromeDriver实例之前将其转换为DesiredCapabilities。
这是我的代码:
ChromeOptions options = new ChromeOptions();
// Setting some chrome features here
ProxyServer proxyServer = new ProxyServer(4444);
proxyServer.start();
Proxy proxy = proxyServer.seleniumProxy();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new ChromeDriver(capabilities); // Error happens here
Run Code Online (Sandbox Code Playgroud)
我正在使用来自Maven存储库的Webdriver版本2.44。这是我得到的错误:
java.lang.IllegalAccessError: tried to access field com.google.gson.JsonNull.INSTANCE from class org.openqa.selenium.remote.BeanToJsonConverter
Run Code Online (Sandbox Code Playgroud)
是否有人知道将代理连接到chromedriver的原因或任何其他解决方案?
java proxy selenium-chromedriver selenium-webdriver browsermob
我通过代理发送一个http请求,需要在我的请求中添加用户名和密码。如何正确将这些值添加到我的选项块?
这是我的代码:
var http = require('http');
var options = {
port: 8080,
host: 'my.proxy.net',
path: '/index',
headers: {
Host: "http://example.com"
}
};
http.get(options, function(res) {
console.log("StatusCode: " + res.statusCode + " Message: " + res.statusMessage);
});
Run Code Online (Sandbox Code Playgroud)
当前,响应为StatusCode:307,消息:Authentication Required。
我试图将用户名和密码添加到我的选项中,但是它不起作用:
var options = {
port: 8080,
host: 'my.proxy.net',
username: 'myusername',
password: 'mypassword',
path: '/index',
headers: {
Host: "http://example.com"
}
};
Run Code Online (Sandbox Code Playgroud)
附加信息: 我没有太多有关代理的信息,但在另一种情况下,此身份验证方法有效:
npm config set proxy http://username:password@my.proxy.net:8080
Run Code Online (Sandbox Code Playgroud) 我有以下脚本使用python selenium Chrome驱动程序访问网页.
from selenium import webdriver
USERNAME = 'usename'
PASSWORD = 'pass'
proxies = ["xxx.xxx.xxx.xxx"]
proxy_tpl ='{0}:{1}'
proxy = proxy_tpl.format(proxies[0],'xx')
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % proxy)
chrome = webdriver.Chrome(chrome_options=chrome_options)
chrome.get("http://{0}:{1}@whatismyipaddress.com".format(USERNAME, PASSWORD))
driver.close()
Run Code Online (Sandbox Code Playgroud)
当我尝试运行脚本时,Chrome仍然会询问用户名和密码.如何从脚本验证代理服务器?
我试图通过经过身份验证的代理获取URL的内容.这是我试图使用的代码:
Authenticator authenticator = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
System.out.println("authenticating");
return (new PasswordAuthentication("username", "password".toCharArray()));
}
};
Authenticator.setDefault(authenticator);
URL url = new URL("http://www.google.com");
InetSocketAddress proxyAddress = new InetSocketAddress("address.of.proxy", 6060);
Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddress);
HttpURLConnection uc = (HttpURLConnection) url.openConnection(proxy);
uc.connect();
System.out.println(uc.getResponseCode());
Run Code Online (Sandbox Code Playgroud)
由于某种原因,身份验证进入重定向循环,因此结果是身份验证器打印"验证"20次,然后是ProtocolException
java.net.ProtocolException: Server redirected too many times (20)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1846)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1439)
at java.net.URLConnection.getContent(URLConnection.java:739)
at proxytest.RunThis.main(RunThis.java:29)
Run Code Online (Sandbox Code Playgroud)
代理正在使用给定的凭据,我已经通过浏览器尝试了它.我试图让这个工作好几天,我已经尝试设置系统属性,apache httpclient,以及任何我可以摆脱谷歌.任何想法都赞赏.:)
更新:
我使用WireShark进行了测试,代理身份验证详细信息在请求中,但代理返回407错误.再次,凭证是好的,它完全从浏览器工作(我实际上从源代码复制它们以确保).
但有一点我注意到了.Proxy-Authorization标头的值在浏览器和java发送的请求之间只有一个字符不同.这意味着什么吗?
java authentication proxy httpurlconnection basic-authentication
我尝试在命令提示符下使用以下命令在我的windows8机器上安装cordova
npm install -g cordova
Run Code Online (Sandbox Code Playgroud)
但由于以下错误我无法安装,任何人都可以帮助我.
错误:
错误的ERR!Windows_NT 6.3.9600 npm ERR!argv"C:\ Program Files \nodejs \\node.exe""C:\ Program Files \nodejs \node_modules \npm\bin \npm-cli.js""install"" - g""cordova"npm ERR!节点v0.12.1 npm ERR!npm v2.5.1 npm ERR!代码ECONNRESET
错误的ERR!无法建立网络隧道套接字,因为= getaddrinfo EN OTFOUND代理npm ERR!网络这很可能不是npm本身的问题npm ERR!网络并与网络连接有关.错误的ERR!网络在大多数情况下,您支持代理或网络设置不良.错误的ERR!网络npm ERR!网络如果您在代理服务器后面,请确保npm ERR!网络'代理'配置设置正确.请参阅:'npm help config'
错误的ERR!请在任何支持请求中包含以下文件:npm ERR!C:\ Users \用户奇迹\ NPM-的debug.log
proxy ×10
java ×3
python ×3
http ×2
node.js ×2
selenium ×2
spring ×2
aspectj ×1
browsermob ×1
cordova ×1
http2 ×1
javascript ×1
netbeans-8 ×1
python-2.7 ×1
tor ×1