SuperAgent

Nodejs - 如何用 eventproxy 模块控制并发

混江龙づ霸主 提交于 2020-01-20 08:56:53
本文转载自: Nodejs - 如何用 eventproxy 模块控制并发 --------- 韩子迟 本文目标 本文的目标是获取 ZOJ 1001-1010 每道题 best solution 的作者 id ,取得数据后 一次性输出 在控制台。 前文 如何用 Nodejs 分析一个简单页面 我们讲了如何用 Nodejs 简单地对一个页面进行分析,我们再来理一理,温故而知新。首先,我们的目标是能输出在页面上,这时我们就需要 http 模块,或者封装了 http 模块的 express 模块。其次我们需要获取博客园首页的页面代码,就要发送 http 请求,而 superagent 模块正是我们所需要的。最后我们要对获取的页面代码进行分析, cheerio 模块能让我们用类似 jQuery 的语法对页面进行解析,何止一个爽字了得! 实践 再看今天我们的任务,粗看之下,少了输出在页面这个条件(不需要用 http 甚至 express 模块了),而需要输出每道题的 best solution 的作者 id,似乎并不是很难,我们来分析下 1001 这道题的 提交统计页面 ,很显然第一条就是最佳 solution 嘛,我们像前面一样用 SuperAgent 模块请求该页面,然后用 cheerio 模块进行解析,不就大功告成了?!什么,要解析 10 个页面?那就发送 10 次 http 请求喽!

用Node+wechaty写一个爬虫脚本每天定时给女(男)朋友发微信暖心话

倾然丶 夕夏残阳落幕 提交于 2020-01-19 21:58:20
wechatBot 微信每日说,每日自动发送微信消息给你心爱的人 项目介绍 灵感来源 在掘金看到了一篇 《用Node + EJS写一个爬虫脚本每天定时女朋友发一封暖心邮件》 后, 在评论区偶然看到一位读者说可不可以用微信实现一下。然后最近刚好在做微信机器人的小项目,那就把这个定时任务放到微信上去做吧,说干就干,撸了一下午终于撸出来了。 项目地址 github: https://github.com/gengchen528/wechatBot 使用库 wechaty - 微信操作 node-schedule - 定时任务 superagent - 爬取页面信息 cheerio - 抓取页面 qrcode-terminal - 终端显示二维码 功能 定时给朋友发送每日天气提醒以及每日一句 根据关键词自动加好友和自动拉群功能 后续继续扩展吧...(你有好的想法也可以提pr) 数据来源 每日一句和上面的大佬一样也是来自 one 天气信息来自 墨迹天气 定时任务 node-schedule 非你莫属了, 可以定时每个月、每个礼拜、每天具体什么时候执行什么任务 实现效果 由于是微信定时发送消息,较邮件来说,微信无法把图片和文字放在同一消息框中,所以美观度来说可能没有邮件好,不过文字进行排版后还是可以的,由于时间仓促,所以文字比较少,后续会继续增加内容; 代码说明 目录结构 config:

Promise Error: Objects are not valid as a React child

戏子无情 提交于 2020-01-09 09:58:11
问题 I am trying to set the json to a state using user agent, I get the error: Uncaught Invariant Violation: Objects are not valid as a React child (found: object with keys {...}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. method to set state: getInitialState: function(){ return { arrayFromJson: [] } }, loadAssessmentContacts: function() { var callback = function(data) { this.setState({arrayFromJson

Promise Error: Objects are not valid as a React child

时光怂恿深爱的人放手 提交于 2020-01-09 09:58:08
问题 I am trying to set the json to a state using user agent, I get the error: Uncaught Invariant Violation: Objects are not valid as a React child (found: object with keys {...}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. method to set state: getInitialState: function(){ return { arrayFromJson: [] } }, loadAssessmentContacts: function() { var callback = function(data) { this.setState({arrayFromJson

React/Redux + super agent, first call gets terminated

无人久伴 提交于 2020-01-03 09:20:09
问题 I am writing a react-redux app where I am making some service calls in my middlewares using superagent. I have found a very strange behavior where the first call to my search api always gets terminated. I have tried waiting 10-30 seconds before making the first call, and logging every step along the process and I cannot seem to pinpoint why this is happening. My action creator looks like export function getSearchResults(searchQuery) { return { query: searchQuery, type: actions.GO_TO_SEARCH

Read Authorization header from response

匆匆过客 提交于 2020-01-02 08:40:10
问题 I am working on a side project in which I want to reuse an existing API. The API has an /auth endpoint which handles POST requests and expects the email and password in the request body. If the email and password are verified, then the server returns a response which contains an Authorization header which holds the value for the token which should be sent in all the subsequent requests. I have a problem retrieving this header from the response. It is visible in both Postman and Chrome Dev

NodeJS/Passport - Testing user login with mocha and superagent

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 07:33:07
问题 I have built a login process with a basic MEAN stack and using passport for the authentication process. I am trying to set up a test to make sure the login process is working. To do the login part here is the code I used: it ('login', function(done) { agent.post(config.web.vhost + '/login') .send({ email: 'bruce@wayne.inc', password: 'batman' }) .end(function(err, res) { if (err) console.log('error' + err.message); res.should.have.status(200); done(); }); }); I get the following error: no

Superagent with absolute url prefix

送分小仙女□ 提交于 2019-12-25 05:51:08
问题 I've noticed that I'm writing http://localhost everytime I want to run a node test with superagent. import superagent from 'superagent'; const request = superagent.agent(); request .get('http://localhost/whatever') .end((err, res) => { ... }); Is there any way of avoiding the localhost part? As far as I've gone is to avoid the request being hardcoded to the host: const baseUrl = 'http://localhost:3030'; request .get(`${baseUrl}/whatever`) But I still have to carry the baseUrl with the agent

Using yield with superagent returns request object instead of response

妖精的绣舞 提交于 2019-12-25 03:45:11
问题 According to SuperAgent docs: SuperAgent docs var res = yield request .get('http://local') .auth('tobi', 'learnboost') However, I'm finding that the var res isn't res, its req. Meaning I have only access to the request object, not the response object with the fetched data that is usually passed to the end() chainable, which is obviously what I need. Anyone experience with this? Am I missing something? 回答1: Although your question was answered on GH, figured I'd paste it here as well for others

Error importing superagent in React code

会有一股神秘感。 提交于 2019-12-22 07:08:31
问题 I have a NodeJS server code written in JSX where I'm importing superagent like so: import request from 'superagent'; When server starts after build, I get the following error: TypeError: require is not a function. And this happens at the following line in my compiled code: var crypto = require('crypto'); On tracing back I realized that crypto is required by 'formidable', which is required by 'superagent'. I have the same superagent import in my client side javascript code but that works fine.