我想在python中为webcrawler自动化oauth2身份验证,我选择使用selenium作为webdriver.
我将不会在我将要使用的机器上拥有root权限,所以我选择使用phantomjs,因为这个脚本需要无头,因此我将无法在这些机器中安装xvfb.
现在我发现phantomJS有这个bug:https://github.com/ariya/phantomjs/issues/10389
我需要使用的oauth2页面有这种重定向,这些页面的解决方法是在javascript中对我来说没用,有一个解决方法(考虑到这些前提)或另一个解决方案在python中完全无头?
我正在尝试使用ptree通过boost message_queue发送json消息来存储信息localy.
这是接收者的代码:
#include <boost/interprocess/ipc/message_queue.hpp>
#include <iostream>
#include <string>
//#include <boost/archive/text_iarchive.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/serialization/string.hpp>
using boost::interprocess::message_queue;
using boost::property_tree::ptree; using boost::property_tree::read_json;
#define MAX_SIZE 1000
int main()
{
message_queue mq (boost::interprocess::open_or_create,"coda",10,MAX_SIZE);
message_queue::size_type recv_size;
unsigned int priority;
ptree pt;
std::stringstream iss;
std::string serialized_string;
serialized_string.resize(MAX_SIZE);
mq.receive(&serialized_string[0],MAX_SIZE,recv_size,priority);
iss << serialized_string;
std::istringstream is(iss.str());
read_json(is, pt);
std::cout pt.get<std::string>("prefix") << pt.get<std::string>("faceID") << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
这是发件人的代码:
#include <boost/interprocess/ipc/message_queue.hpp>
#include <boost/serialization/string.hpp>
#include <string>
#include <sstream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
using boost::interprocess::message_queue;
using boost::property_tree::ptree; using boost::property_tree::write_json;
#define MAX_SIZE …Run Code Online (Sandbox Code Playgroud) 我正在解决蟒蛇的问题.直到第34天我才有任何实际问题.
这就是问题:
项目:创建代理类
在此分配中,创建一个代理类(下面将为您启动一个代理类).您应该能够使用任何对象初始化代理对象.应将代理对象上调用的任何属性转发到目标对象.在发送每个属性调用时,代理应记录发送的属性的名称.
代理类是为您启动的.您将需要添加方法缺少处理程序和任何其他支持方法.Proxy类的规范在AboutProxyObjectProject koan中给出.
注意:这有点棘手,它是Ruby Koans的对应物,但你可以做到!
这是我的解决方案,直到现在:
class Proxy(object):
def __init__(self, target_object):
self._count = {}
#initialize '_obj' attribute last. Trust me on this!
self._obj = target_object
def __setattr__(self, name, value):pass
def __getattr__(self, attr):
if attr in self._count:
self._count[attr]+=1
else:
self._count[attr]=1
return getattr(self._obj, attr)
def messages(self):
return self._count.keys()
def was_called(self, attr):
if attr in self._count:
return True
else: False
def number_of_times_called(self, attr):
if attr in self._count:
return self._count[attr]
else: return False
Run Code Online (Sandbox Code Playgroud)
它适用于此测试:
def test_proxy_records_messages_sent_to_tv(self):
tv = Proxy(Television()) …Run Code Online (Sandbox Code Playgroud)