首页 \ 问答 \ 从rethinkdb获取条目到node.js博客(get entries from rethinkdb to node.js blog)

从rethinkdb获取条目到node.js博客(get entries from rethinkdb to node.js blog)

我想制作一个简单的节点博客,但我需要一些帮助!

我想将我的博客“条目”或“帖子”保存到rethinkdb,但为了做到这一点,我首先需要知道如何让我的帖子显示在我的博客上,所以我创建了一个rethinkdb服务器,带有一些条目! 这是它的样子:

[

    {
        "body": "This is the standard hello world message!" ,
        "id": "1" ,
        "published": "2014-04-19" ,
        "title": "Hello World!" 
    } ,
    {
        "body": "I tought dinner with my family would be horrific, but maybe my low expectations made it bearable" ,
        "id": "3" ,
        "published": "2014-04-19" ,
        "title": "Dinner was ok!" 
    } ,
    {
        "body": "Here I am ranting about how easter is not as awesome it is said to be" ,
        "id": "2" ,
        "published": "2014-04-19" ,
        "title": "Easter is hard work" 
    } 

] 

数据库名称为'blogdb',表名为'entries'

这是我的app.js(node.js服务器)

/**
 * Module dependencies.
 */

var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));

app.use(express.bodyParser());

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', function(req, res) {
    res.render('index',
    {title: 'My Blog'}
    )
});

app.get('/about', function(req, res) {
    res.render('about',
    { title : 'About' }
    )
})

app.get('/photos', function(req, res) {
    res.render('photos',
    { title : 'Photos' }
    )
})

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

最后,我们有index.jade(网页)

extend layout
block content
    p this is where I want my entreis to be!
    footer
      p
        a(href='/') Home
        | ~
        a(href='/about') About Me
        | ~
        a(href='/photos') Some photos

我知道这并不多,但在我参加之前我并不想做太多的设计!

我必须做什么才能将我的所有条目从rethinkdb服务器放入我的网页?

所有帮助表示赞赏!


I want to make a simple node blog, but I need some help!

I want to save my blog 'entries' or 'posts' to rethinkdb, but to do that I first need to know how to get my posts to show up on my blog, so I made a rethinkdb server, with some entries! this is what it looks like:

[

    {
        "body": "This is the standard hello world message!" ,
        "id": "1" ,
        "published": "2014-04-19" ,
        "title": "Hello World!" 
    } ,
    {
        "body": "I tought dinner with my family would be horrific, but maybe my low expectations made it bearable" ,
        "id": "3" ,
        "published": "2014-04-19" ,
        "title": "Dinner was ok!" 
    } ,
    {
        "body": "Here I am ranting about how easter is not as awesome it is said to be" ,
        "id": "2" ,
        "published": "2014-04-19" ,
        "title": "Easter is hard work" 
    } 

] 

the database name is 'blogdb' and the table name is 'entries'

And this is my app.js (node.js server)

/**
 * Module dependencies.
 */

var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));

app.use(express.bodyParser());

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', function(req, res) {
    res.render('index',
    {title: 'My Blog'}
    )
});

app.get('/about', function(req, res) {
    res.render('about',
    { title : 'About' }
    )
})

app.get('/photos', function(req, res) {
    res.render('photos',
    { title : 'Photos' }
    )
})

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

And last, we have index.jade (the webpage)

extend layout
block content
    p this is where I want my entreis to be!
    footer
      p
        a(href='/') Home
        | ~
        a(href='/about') About Me
        | ~
        a(href='/photos') Some photos

I know it's not much, but I didn't feel like doing much design before I have my entries there!

What must I do to get all my entries from the rethinkdb server into my webpage?

all help is appreciated help!


原文:https://stackoverflow.com/questions/23173752
更新时间:2022-03-24 21:03

最满意答案

你需要做两件事:

  • 加载图像,因为在未加载图像时按钮没有尺寸。
  • 点击后稍等一下。 CasperJS似乎没有发现有页面加载发生。

完整脚本:

var casper = require('casper').create({   
    //verbose: true, 
    //logLevel: 'debug',
    pageSettings: {
         loadImages:  true,         
         loadPlugins: false,       
         userAgent: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36'
    }
});

var x = require('casper').selectXPath;

var acceptBtn = x("//input[contains(@value, 'Cookies accepteren')]");

casper.start('http://www.marktplaats.nl', function() {
        this.echo(this.getTitle());
    })
    .waitForSelector(acceptBtn)
    .thenClick(acceptBtn)
    .wait(100)
    .then(function(){
        this.echo(this.getTitle());
    })
    .run();

You need to do two things:

  • Load images, because it seems as the button has no dimensions when images are not loaded.
  • Wait a bit after clicking. CasperJS doesn't seem to pick up that there is a page load happening.

Full script:

var casper = require('casper').create({   
    //verbose: true, 
    //logLevel: 'debug',
    pageSettings: {
         loadImages:  true,         
         loadPlugins: false,       
         userAgent: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36'
    }
});

var x = require('casper').selectXPath;

var acceptBtn = x("//input[contains(@value, 'Cookies accepteren')]");

casper.start('http://www.marktplaats.nl', function() {
        this.echo(this.getTitle());
    })
    .waitForSelector(acceptBtn)
    .thenClick(acceptBtn)
    .wait(100)
    .then(function(){
        this.echo(this.getTitle());
    })
    .run();

相关问答

更多
  • Cookie政策由以下方式管理: [NSHTTPCookieStorage sharedHTTPCookieStorage].cookieAcceptPolicy 默认值为: NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain 也就是说,只接受来自主文档域(当前打开的html文档的域)的cookie。 相关的枚举是: typedef NS_ENUM(NSUInteger, NSHTTPCookieAcceptPolicy) { NSHTTPCoo ...
  • 我结束了使用NodeJS'child_process: https ://nodejs.org/api/child_process.html这几乎是我想要的,并使用我已经在CasperJS脚本中使用过的相同语言。 教程和我使用的示例: https : //era86.github.io/2012/10/11/quick-and-dirty-nodejs-exec-limit-queue.html I ended up using NodeJS' child_process: https://nodejs.o ...
  • 你做不到 如果该网站已正确实施,则会将您的Cookie保存为仅在浏览器中无法访问的HTTP。 想象一下,如果这是可能的话,每个人都可以(只需很少的调查时间)欺骗cookie并访问系统。 You can't do it If the site is implemented correctly it will save your cookie as a HTTP-only which you can't access in browser. Imagine if this was possible, every ...
  • 不,没有办法直接做到。 你需要间接地做。 请记住,CasperJS构建于PhantomJS之上,PhantomJS具有与node.js不同的执行环境。 很少有node.js模块实际上在PhantomJS / CasperJS内部无需更改。 您必须编写一个脚本(例如node.js脚本),该脚本能够读取文件并写入MySQL。 CasperJS脚本擦除数据并将数据存储在某个(临时)文件中(参见PhantomJS的fs模块 ), 使用已删除的数据文件调用外部脚本(请参阅PhantomJS的child_process ...
  • 你需要做两件事: 加载图像,因为在未加载图像时按钮没有尺寸。 点击后稍等一下。 CasperJS似乎没有发现有页面加载发生。 完整脚本: var casper = require('casper').create({ //verbose: true, //logLevel: 'debug', pageSettings: { loadImages: true, loadPlugins: false, ...
  • 对于您的开发工作,您可以坚持使用single_host_origin或使用none (效率较低)。 当您的登录用户可能使用多个协议(http和https)或子域(www.example.com和support.example.com)访问您的网站时,Cookie政策更为重要。 在这些情况下,您可能希望使用http://example.com的cookie政策 For your development work, you can stick with single_host_origin or use non ...
  • 发现问题来自phantomjs: #phantomjs hello.js child_process.js:936 var r = this._handle.spawn(options); ^ TypeError: Bad argument at ChildProcess.spawn (child_process.js:936:24) at exports.spawn (child_process.js:736:9) at Obje ...
  • 只需重新创建整个CookieManager类:以下是该类的来源: http ://jarvana.com/jarvana/view/net/sourceforge/htmlunit/htmlunit/2.8/htmlunit-2.8-sources.jar!/com/gargoylesoftware/htmlunit /CookieManager.java?format=ok 现在在那里查找这个方法public synchronized Set getCookies(final URL ur ...
  • 我们已在您的计算机上放置了cookie,以帮助改善本网站。 您可以随时更改Cookie设置。 否则,我们假设您可以继续。 ICO的网站现在显示用户必须选择退出,而不是选择加入。上面的报价显示了他们如何在他们的网站上实施它。 这意味着最好的想法可能是在您网站顶部放置一个横幅,向他们展示类似的信息。 如果用户不想使用cookie,他们可以在浏览器中自行禁用它们。 它似乎不是网站所有者实施cookie删除策略。 We have placed cookies on your computer to help mak ...
  • 您可以从“resource.requested”事件中止任何网络请求。 如果您知道iframe网址,则可以应用此网址。 You can abort any network request from the "resource.requested" event. If you know the iframe URL, then this can be applied.

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)