从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
最满意答案
你需要做两件事:
- 加载图像,因为在未加载图像时按钮没有尺寸。
- 点击后稍等一下。 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和MySQL(CasperJS and MySQL)[2023-01-21]
不,没有办法直接做到。 你需要间接地做。 请记住,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 ...
-
htmlunit中的Cookie策略(Cookie policy in htmlunit)[2023-07-07]
只需重新创建整个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 SetgetCookies(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.