我是第一次尝试phantomJS并且我已成功从站点中提取som数据,但是当我尝试将某些内容写入文件时,我得到错误:ReferenceError:找不到变量:fs
这是我的剧本
var page = require('webpage').create();
var fs = require('fs');
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open("http://www.pinterest.com/search/pins/?q=motorbike", function(status) {
if (status === "success") {
page.includeJs("http://code.jquery.com/jquery-latest.js", function() {
page.evaluate(function() {
var imgs = {
title: [],
href: [],
ext: [],
src: [],
alt: []
};
$('a.pinImageWrapper').each(function() {
imgs.title.push($(this).attr('title'));
imgs.href.push($(this).attr('href'));
var ext = $(this).children('.pinDomain').html();
imgs.ext.push(ext);
var img = $(this).children('.fadeContainer').children('img.pinImg');
imgs.src.push(img.attr('src'));
imgs.alt.push(img.attr('alt'));
});
if (imgs.title.length >= 1) {
for (var i = 0; i < imgs.title.length; i++) {
console.log(imgs.title[i]);
console.log(imgs.href[i]);
console.log(imgs.ext[i]);
console.log(imgs.src[i]);
console.log(imgs.alt[i]); …Run Code Online (Sandbox Code Playgroud) 我正在开发一个简单的WPF应用程序,其唯一目的是使用Renci SSH.net库获取SshClient的工作目录,并将其进一步传递给SftpClient。
我似乎无法通过使用从RunCommand(“ pwd”)返回的绝对路径来使用sftpClient.ChangeDirectory更改目录。我肯定知道该路径确实存在,因为SshClient返回了它,但是也许我做错了什么,还是有一个错误?无论哪种方式,这是我的代码:
public static string ssh_host,
ssh_username,
ssh_password,
workingDirectory;
public MainWindow()
{
InitializeComponent();
ssh_host = "XXXXXXXXXX";
ssh_username = "XXXXXXXXXX";
ssh_password = "XXXXXXXXXX";
StartSSH();
}
private static void StartSSH()
{
using (var client = new SshClient(ssh_host, ssh_username, ssh_password))
{
try
{
client.Connect();
if (client.IsConnected)
{
Console.WriteLine("Client connected");
SshCommand getSSHWorkingDirectory = client.RunCommand("pwd");
workingDirectory = getSSHWorkingDirectory.Result;
Console.WriteLine("SSH working directory = " + workingDirectory);
// RESULT: SSH working directory = /customers/5/7/9/domain.com/httpd.private
using (var sftpClient = new SftpClient(ssh_host, ssh_username, ssh_password))
{
sftpClient.Connect();
if …Run Code Online (Sandbox Code Playgroud) 我是游戏编程和C#的新手,但我有一些javaScript和PHP的编程经验.
好的,我们去,我有一个C#脚本,我想用于怪物生成.我在Youtube上关注了Tom Adamson,直到他开始产生随机值:UNITY3D C#和Tom Adamson
这是我的脚本:
using UnityEngine;
using System.Collections;
public class myMonster : MonoBehaviour {
public class aMonster {
//The properties
public int id;
public int age;
public string name;
public string race;
public int health;
//A method
public void monsterData() {
print("ID: " + id);
print("Race: " + race);
print("Name: " + name);
print("Age: " + age);
print("Health: " + health);
}
} // End of class definition
//-----------------------------------------------------------------------------------------
void Start () {
aMonster[] bigMonster = new …Run Code Online (Sandbox Code Playgroud) 我有一个任务,我需要解析C#脚本并寻找某个方法属性并从中提取部分,我想知道是否有一种比我更优雅的方式:
[Info("Title", "Author", "5.2.5", ResourceId = 819)]
这是我做的:
// foreach line in script
if (line.Contains("[Info(") && line.Contains("ResourceId"))
{
var _attributes = line
.Replace(" ", "")
.Replace("\"", "")
.Replace("[Info(", "")
.Replace(")]", "")
.Replace("ResourceId=", "")
.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
// Do stuff with _attributes[0] _attributes[1] etc..
break;
}
Run Code Online (Sandbox Code Playgroud) 我编写了简单的代码,由于获得NullReferenceException的原因我不知道,由于某些特殊原因无法正常工作.
这是简单的应用程序
namespace App1
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private string[] IPToCheck;
private List<string> IPRange;
private bool CorrectNetwork = false;
public MainPage()
{
this.InitializeComponent();
var hostnames = NetworkInformation.GetHostNames();
foreach (var hn in hostnames)
{
if (hn.IPInformation != null &&
(hn.IPInformation.NetworkAdapter.IanaInterfaceType == 71
|| hn.IPInformation.NetworkAdapter.IanaInterfaceType == 6))
{
IPToCheck = hn.DisplayName.Split(new char[] { '.' });
if …Run Code Online (Sandbox Code Playgroud)