我正在使用phantomjs
编写一个脚本,该脚本提取网页请求和响应的某些功能。我已经在phantomjs
示例上添加了here以及页面中引用的netsniff.js
示例的脚本。为了使请求与其特定响应相匹配,我创建了一个名为page.resources的对象对象,该对象通过url索引。问题是我的代码中没有设置对象。我的代码在下面复制/粘贴。
在这里,我首先创建一个page.resources
对象,然后在每次调用onResourceRequested
时,插入一个具有某些属性的对象。当我在创建内部对象之后尝试访问时,我无法执行此操作。此外,当我尝试访问onResourceReceived
中的同一个对象时,我没有输出。有人可以帮忙吗?我曾尝试在代码的不同位置使用console.log
进行调试,但我无法弄清楚可能出现的问题。
"use strict";
var page = require('webpage').create(),
system = require('system'),
address;
if (system.args.length === 1) {
console.log('Usage: netsniff.js <some URL>');
phantom.exit(1);
} else {
address = system.args[1];
page.resources = {}
page.redirectedURLs = {}
page.onResourceRequested = function (req) {
console.log("Resource requested: " + req.url)
page.resources[req.url] = {
url: url,
redirected: null, //will be set in response
redirectedURL: null, //will be set in response
HSTS: null,
maxage: null,
includeSubdomains: null
};
//Can't access the object over here
console.log("accesing page resources" + page.resources[req.url].url);
};
page.onResourceReceived = function (res) {
//Can't access the object over here either
for (var key in page.resources) {
if (pageresources.hasOwnProperty(key)) {
console.log(key + " -> " + page.resources[key].url);
}
}
};
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
}
});
page.onLoadFinished = function(response) {
phantom.exit()
};
}
答案 0 :(得分:1)
你有一个错字:
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
double value=90.753/3;//the numerator & denominator came from certain computations
Button button1 = new Button();
button1.Font = new Font("Arial", value, FontStyle.Bold);
}
}
}