当我的xpath选择器的结果返回None时,我试图设置默认值.当在某些页面中xpath节点不存在并且我想设置例如'N/A'或'Not found'时会发生这种情况.
我使用了以下代码,但我认为这不是干净而有效的:
value = response.xpath(property.xpath).extract_first()
if(value != None):
data[property.name] = response.xpath(property.xpath).extract_first()
else:
data[property.name] = "N/A"
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢
我有一个在 Bluemix 中使用 Docker 容器部署微服务的项目。所有微服务都是用 Java 编写的,通信使用 JKS 文件。
我还在 Node.js 中使用 Express.js 开发了一个微服务。为了使用其他微服务,我使用了带有option.agentOptionsfeature 和 a的 Request 模块pfx file,如下所示:
var options = {
uri: config.get("https://www.example.com/ms/service"),
method: 'POST',
body: data,
json: true,
headers: {
'Content-Type': 'application/json; charset=UTF-8'
},
agentOptions: {
pfx: fs.readFileSync(config.get("/path/to/file.pfx")),
passphrase: config.get("passphraseText"),
servername: config.get("serverName")
}
};
request(options, function (error, response, data) {
//handing response
});
Run Code Online (Sandbox Code Playgroud)
我尝试将 Solicit crate与HTTPS 的默认示例一起使用,但它失败了:
var options = {
uri: config.get("https://www.example.com/ms/service"),
method: …Run Code Online (Sandbox Code Playgroud)