我想在R中创建一个ping给定网站的脚本.我没有找到任何有关此特定信息的信息.
首先,我需要的是有关网站是否响应ping的信息.
有没有人有关于现有脚本的信息或最适合使用的包?
我正在尝试使用CasperJS来抓取一个拥有动态内容并且到目前为止失败的网站.该网站使用几个js库(例如Prototype)来使用自动完成来创建内容.因此,我试图插入一些值并触发事件以引发内容创建.插入和触发事件可以正常工作,但不会创建任何内容.
我是CasperJS的新手,发现它与库的相对路径有问题.我怀疑我的问题来自于在我的页面环境中没有正确加载的库.因此我试着injectJs像这样注射它们
// ...创建casper并做一些其他的事情
casper.then(function(){
Run Code Online (Sandbox Code Playgroud)this.echo(this.page.injectJs('http://www.my-website.com/path/to/js1')); this.echo(this.page.injectJs('http://www.my-website.com/path/to/js2')); });
不幸的是,这两个函数都返回false.脚本的路径是正确的,在哪里可能是这个问题的根源?
非常感谢您的帮助.
我试图将数组作为第一个元素插入到多维数组中.我的原始数组的示例
Array (
0 => array ( "point1.0" => "some data", "point2.0" => "some data" )
1 => array ( "point1.1" => "some data", "point2.1" => "some data" )
)
Run Code Online (Sandbox Code Playgroud)
然后我将要插入的数组作为第一个元素
$newArray = array("point1.2" => "some data", "point2.2" => "some data" )
Run Code Online (Sandbox Code Playgroud)
我的结果应该是
Array (
0 => array ( "point1.2" => "some data", "point2.2" => "some data" )
1 => array ( "point1.0" => "some data", "point2.0" => "some data" )
2 => array ( "point1.1" => "some data", "point2.1" …Run Code Online (Sandbox Code Playgroud) 我对ggplot比较新,所以如果我的一些问题非常简单或根本无法解决,请原谅我.
我想要做的是生成一个国家的"热图",其中形状的填充是连续的.此外,我有国家的形状.RData.我使用hadley wickham的脚本将我的SpatialPolygon数据转换为数据框.我数据框的long和lat数据现在看起来像这样
head(my_df)
long lat group
6.527187 51.87055 0.1
6.531768 51.87206 0.1
6.541202 51.87656 0.1
6.553331 51.88271 0.1
Run Code Online (Sandbox Code Playgroud)
这个长/拉数据描绘了德国的轮廓.这里省略了数据框的其余部分,因为我认为不需要它.对于某些长/纬度点,我还有第二个数据帧.这看起来像这样
my_fixed_points
long lat value
12.817 48.917 0.04
8.533 52.017 0.034
8.683 50.117 0.02
7.217 49.483 0.0542
Run Code Online (Sandbox Code Playgroud)
我现在想做的是,根据位于该点一定距离内的所有固定点的平均值,为地图的每个点着色.这样我就可以得到整个国家地图的(几乎)连续着色.到目前为止我所拥有的是用ggplot2绘制的国家地图
ggplot(my_df,aes(long,lat)) + geom_polygon(aes(group=group), fill="white") +
geom_path(color="white",aes(group=group)) + coord_equal()
Run Code Online (Sandbox Code Playgroud)
我的第一个想法是生成位于已绘制的地图内的点,然后计算每个生成点的值,my_generated_point如此
value_vector <- subset(my_fixed_points,
spDistsN1(cbind(my_fixed_points$long, my_fixed_points$lat),
c(my_generated_point$long, my_generated_point$lat), longlat=TRUE) < 50,
select = value)
point_value <- mean(value_vector)
Run Code Online (Sandbox Code Playgroud)
我还没有找到一种方法来产生这些点.就像整个问题一样,我甚至不知道是否有可能以这种方式解决.我现在的问题是,是否存在生成这些点的方法和/或是否有另一种方法来解决问题.
解
感谢Paul,我几乎得到了我想要的东西.以下是荷兰样本数据的示例.
library(ggplot2)
library(sp)
library(automap)
library(rgdal)
library(scales)
#get the spatial data …Run Code Online (Sandbox Code Playgroud) R中的arules包使用"事务"类.所以为了使用apriori()我需要的功能来转换我现有的数据.我有一个有2列和大约1.6毫米行的矩阵并尝试转换数据,如下所示:
transaction_data <- as(split(original_data[,"id"], original_data[,"type"]), "transactions")
Run Code Online (Sandbox Code Playgroud)
其中original_data是我的数据矩阵.由于数据量的原因,我使用了最大的AWS亚马逊机器,内存为64GB.过了一会儿,我明白了
结果向量超过'AnswerType'中的向量长度限制
机器的内存使用率仍然只有60%.这是基于R的限制吗?除了使用采样之外,还有什么方法可以解决这个问题吗?当仅使用1/4的数据时,转换工作正常.
编辑:正如所指出的,其中一个变量是一个因素而不是字符.更改后的转换处理快速正确.
我使用ClientLogin方法和cURL登录google API.这工作正常,我收到一个令牌供进一步使用.我现在可以使用查询docs.google.com
$curl = curl_init();
$headers = array(
"Authorization: GoogleLogin auth=" . $auth,
"GData-Version: 3.0",
);
curl_setopt($curl, CURLOPT_URL, "https://docs.google.com/feeds/default/private/full");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
curl_close($curl);
Run Code Online (Sandbox Code Playgroud)
这工作正常,我得到了我的谷歌文档帐户中可用的所有文档的列表.但是,如果我使用从api文档中获取的URL对spreadsheets.google.com尝试相同的查询:
https://spreadsheets.google.com/feeds/spreadsheets/private/full
Run Code Online (Sandbox Code Playgroud)
我收到401错误,说明使用的令牌无效.我在两种情况下都使用相同的标记和查询.我是否需要为Google电子表格API提供不同的令牌?
编辑:这是我请求令牌的方式:
$clientlogin_url = "https://www.google.com/accounts/ClientLogin";
$clientlogin_post = array(
"accountType" => "HOSTED_OR_GOOGLE",
"Email" => "my email",
"Passwd" => "my password",
"service" => "writely",
"source" => "my application name"
);
$curl = curl_init($clientlogin_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, …Run Code Online (Sandbox Code Playgroud) r ×3
php ×2
apriori ×1
arrays ×1
automap ×1
bigdata ×1
casperjs ×1
curl ×1
ggplot2 ×1
javascript ×1
phantomjs ×1
ping ×1
transactions ×1
web-scraping ×1