V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  gxz  ›  全部回复第 1 页 / 共 1 页
回复总数  2
2020-04-23 16:45:33 +08:00
回复了 gxz 创建的主题 Node.js [爬虫] nightmare cookies 问题
问题解决了,是需要在 nightmare 执行 goto 前给 cookie 赋值。也许需要这样处理:

Nightmare.action('preloadCookies',
function(name, options, parent, win, renderer, done) {
parent.on('did-start-loading', function(url, sessionCookies) {
if (sessionCookies) {
parent.emit('log', 'Preloading cookies');

for (var i = 0; i < sessionCookies.length; i++) {
var details = Object.assign({ url: url }, sessionCookies[i]);
win.webContents.session.cookies.set(details, function (error) {
if (error) done(error);
});
}
}
parent.emit('did-start-loading');
});
done();
return this;
},
function(cookies, url, done) {
this.child.once('did-start-loading', done);

this.child.emit('did-start-loading', url, cookies);
});

let cookies = storage.getItemSync(process.env.COOKIES_STORAGE);
let url = storage.getItemSync(process.env.URL_STORAGE);

Nightmare().preloadCookies(cookies, url).goto(url);
2020-04-22 19:54:23 +08:00
回复了 gxz 创建的主题 MySQL 网站消息表设计问题
在我一目十行之下看了一些 MySQL 性能的书籍之后,问题暂时解决惹。
现在消息显示根据不同模板( TYPE 值)方式如:
> XXX 回复了你的评论
> (评论前 90 字内容)
> [查看]

XXX 根据 `CRT_UID` 在 `user_basic` 中取得用户名和头像,
回复了你的评论 根据 `TYPE` 得到,
(评论前 90 字内容)为 `SRE_DETAIL` 字段
查看操作根据需要通过 `SRE_ID` 在指定表中取得数据。( TYPE )

msg 表如下:
```
| 名字 | 类型 | 注释 |
| :--------- | :----------- | :------- |
| ID | int(11) | |
| TYPE | tinyint(4) | |
| STATUS | tinyint(4) | |
| UID | int(11) | 接收者 |
| SRE_ID | int(11) | 来源 ID |
| SRE_DETAIL | varchar(255) | 来源标题 |
| CRT_UID | int(11) | 创建人 |
| CRT_DT | datetime | 创建时间 |
```
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5669 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 13ms · UTC 07:17 · PVG 15:17 · LAX 00:17 · JFK 03:17
Developed with CodeLauncher
♥ Do have faith in what you're doing.