请问一下大大,现在数据爬取成功了,想对数据进行处理。请问怎么把某一项数据导出来?比如我想要导出发的微博中包含“发财”的博主名到另一个表或excel里,要怎么写语句呀?
感谢反馈,如果是mysql,可以在mysql命令行这样写sql语句:
create table NewTable select distinct user.nickname from weibo, user where locate('发财', weibo.content) and weibo.user_id=user.id;
其中NewTable是新表的表名,你可以按自己修改名字。
感觉作者可以考虑写个前端了;
直接用PHPmyadmin的也可以。
啊啊啊啊我忘记说我用的是mongo,用的工具是robo 3t------------------ 原始邮件 ------------------ 发件人: "Chen Lei"[email protected] 发送时间: 2020年5月14日(星期四) 中午1:25 收件人: "dataabc/weiboSpider"[email protected]; 抄送: "ooonice"[email protected];"Author"[email protected]; 主题: Re: [dataabc/weiboSpider] 请问一下大大,现在数据爬取成功了,想对数据进行处理。请问怎么把某一项数据导出来?比如我想要导出发的微博中包含“发财”的博主名到另一个表或excel里,要怎么写语句呀? (#148)
感谢反馈,如果是mysql,可以在mysql命令行这样写sql语句:
create table NewTable select distinct user.nickname from weibo, user where locate('发财', weibo.content) and weibo.user_id=user.id;
其中NewTable是新表的表名,你可以按自己修改名字。
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
@modun 感谢建议,因为每个用户需求不同,很多都是只用csv保存数据,没有用到数据库,添加数据库相关的前端可能会增加他们的使用成本,其次已经有了像PHPmyadmin这种不错的软件,没必要开发了。还有就是自己心力不足,暂时没有余力。
再次感谢热心的建议,如果还有其它建议,欢迎继续讨论:smile:
mongo可以在命令行通过如果命令实现:
db.user.aggregate([{
$lookup: {
from: "weibo",
localField: "id",
foreignField: "user_id",
as: "wb_info"
}},
{$match: {wb_info:{ $elemMatch:{content: /发财/}}}},
{$project: {nickname:1}},
{$out: 'new_table'}
]);
其中new_table是新集合的名字,可以自己修改
再请问一下大大,如果我想统计一些字段,这些字段有的是空有的是有数据存在,我想把空设为0非空设为1最后输出出来到新的集合,这可以实现吗?(mongo语言)
db.weibo.aggregate(
[
{
$project: {
id: 1,
content:1,
original_pictures: {$cond: [ { $eq: [ "$original_pictures", "无" ] }, 0, 1 ]}
}
},
{$out: 'new_table'}
]
)
上面是以筛选weibo表的原始图片为例的,我想保留id和content属性,所以对应值为1。mongo中original_pictures值要么为“无”,要么为url,前者赋值为0,后者为1,new_table为新表名。
啊啊啊啊啊太感谢了!!!!
大大,之前通过您aggregate这个代码得出来一个表,现在想对这个表进行初筛,比如这个表里的语句是这样的: { "user_id" : "2573066491", "wb_info" : [ { "id" : "IEI2K5VdD", "content" : " abc", "publish_time" : "2020-05-05 07:41", }, { "id" : "Ihusoc", "content" : " hui", "publish_time" : "2020-05-05 07:41", }, ] } 我想创建一个新表,里面包括user_id、web_info里的id(这个id要求content内容含有“ab”并且publish_time是最早的)这两项,要怎实现?
看了很多对内嵌表的操作,实在是没找到答案,太难了吧
这个我也没想明白
啊我死掉了。。。
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Closing as stale, please reopen if you'd like to work on this further.