这真让我抓狂.
我想在QWebPage中显示一个url,但我想通过一个无限的代理来传递它.
码
#setting up the proxy
proxy = QNetworkProxy()
proxy.setHostName("189.75.98.199") #just examples
proxy.setPort(1111)
proxy.setType = QNetworkProxy.HttpProxy
#setting the manager
manager = QNetworkAccessManager()
manager.setProxy(proxy) #setting the proxy on the manager
#setting the proxy as application proxy
QNetworkProxy.setApplicationProxy(proxy) #seems to do nothing..
#web page
webpage = QWebPage()
webpage.setNetworkAccessManager(manager) #maybe.. but it doesn't work
webpage.mainFrame().load(QUrl("http://www.foo.bar") )
我调用一个测试页面告诉我标题(在PHP服务器上,所以我看看$_SERVER),而remote_addr总是我的ip,而不是代理ip.
怎么了?
你能帮助我吗?我正在使用PyQt 4.8.3.
最佳答案
让它工作
原文链接:https://www.f2er.com/python/439120.html以这种方式,它使用setApplicationProxy工作.我仍然不明白为什么在实例创建后设置代理参数不起作用(如在初始示例中)
def set_proxy(self,proxy):
proxy_url = QUrl(proxy)
if unicode(proxy_url.scheme()).startswith('http'):
protocol = QNetworkProxy.HttpProxy
else:
protocol = QNetworkProxy.Socks5Proxy
QNetworkProxy.setApplicationProxy(
QNetworkProxy(
protocol,proxy_url.host(),proxy_url.port(),proxy_url.userName(),proxy_url.password()))