SuperAgent

Problems fetching data from a SSL based Server

拜拜、爱过 提交于 2019-12-07 23:23:46
问题 I had a Backend which wasn´t SSL based (http:.....). Everything worked just great. I am developing an Android and iOS App with React Native. I used superagent as my request client. So after i had changed my backend to SSL (https:...) i get the [TypeError: Network request failed] error on all GET/POST etc. Now maybe i have to save the ssl - certificate or something like that, but didn´t find anything that worked. Maybe someone experienced the same/similar issue and could help me out? 来源: https

五、nodejs使用 eventproxy 控制并发

僤鯓⒐⒋嵵緔 提交于 2019-12-07 19:35:18
目标 爬取 CNode( https://cnodejs.org/ ) 社区首页的标题和详情页的第一条评论,以及评论的作者,作者积分,最后以json格式打印 步骤 注意:很多网站有并发连接数的限制,所以当请求发送太快的时候会导致返回值为空或报错。 安装依赖 express superagent cheerio eventproxy $ npm install express superagent cheerio eventproxy --save 新建app.js 抓取所有的url // 引入依赖 var express = require('express'); var eventproxy = require('eventproxy'); var superagent = require('superagent'); var cheerio = require('cheerio'); var app = express(); // url 模块是 Node.js 标准库里面的 var url = require('url'); var cnodeUrl = 'https://cnodejs.org/'; app.get('/', function(req, res, next) { // 用 superagent 去抓取 https://cnodejs.org/ 的内容

Cannot Basic Auth from React App with Axios or SuperAgent

谁说胖子不能爱 提交于 2019-12-07 05:55:37
问题 I try to make a GET request with axios and I always get 401. This happens only when I send the request from my react app. axios.get('http://localhost:8080/vehicles', { withCredentials: true, auth: { username: 'admin', password: 'admin' }, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, }) Postman GET request with the same credentials and Basic Auth set, works. If I simply type in my browser the url, a login box appears and with the same credentials, it works, I

【HAVENT原创】superagentCallback*** is not defined

£可爱£侵袭症+ 提交于 2019-12-06 21:17:14
在使用 superagent-jsonp 跨域调用过程中,直接报错:Uncaught ReferenceError: superagentCallback*** is not defined 根本原因是callback已经被浏览器回收了,通过设置timeout时间该问题可以解决 .use(jsonp({timeout: 10000})) 调用示例代码如下: import request from 'superagent' import jsonp from 'superagent-jsonp' const state = { body: {} }; const mutations = { getMovies (state, response) { switch (response.tag) { case 'hotMovies': state.body = response; break; default: state.body = response; } } }; const actions = { getMovies ({ commit }, params) { request .get('https://api.douban.com/v2/movie/in_theaters?count=8') .accept('json') .use(jsonp({timeout: 10000

用NodeJS实现一个网络爬虫小应用-爬取博客园首页文章列表

隐身守侯 提交于 2019-12-05 21:57:30
前言    网络爬虫 (又称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本。另外一些不常使用的名字还有蚂蚁、自动索引、模拟程序或者蠕虫。   我们可以使用网络爬虫对数据信息进行自动采集,比如应用于搜索引擎中对站点进行爬取收录,应用于数据分析与挖掘中对数据进行采集,应用于金融分析中对金融数据进行采集,除此之外,还可以将网络爬虫应用于舆情监测与分析、目标客户数据的收集等各个领域。 1、网络爬虫分类   网络爬虫按照系统结构和实现技术,大致可以分为以下几种类型: 通用网络爬虫 (General Purpose Web Crawler)、 聚焦网络爬虫 (Focused Web Crawler)、 增量式网络爬虫 (Incremental Web Crawler)、 深层网络爬虫 (Deep Web Crawler)。 实际的网络爬虫系统通常是几种爬虫技术相结合实现的,下面分别对这几种爬虫加以简单的介绍。 1.1、通用网络爬虫 又称全网爬虫(Scalable Web Crawler),爬行对象从一些种子URL扩充到整个Web,主要为门户站点搜索引擎和大型Web服务提供商采集数据。 1.2、聚焦网络爬虫 又称主题网络爬虫(Topical Crawler),是指选择性地爬行那些与预先定义好的主题相关页面的网络爬虫。

Read Authorization header from response

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 19:59:25
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 Tools (Network section). Chrome Dev tools: console.log of the response headers I have tried multiple

Node js 相关知识总结

本秂侑毒 提交于 2019-12-05 14:43:32
参考教程: https://github.com/alsotang/node-lessons/blob/master/lesson4/app.js 一. 利用cheerio实现网络爬虫 示例代码: //利用cheerio实现网络爬虫 var express = require ( 'express' ); //一个 Node.js 版的 jquery,用来从网页中以 css selector 取数据,使用方式跟 jquery 一样一样的 var cheerio = require ( 'cheerio' ); // http 方面的库,可以发起 get 或 post 请求 var superagent = require ( 'superagent' ); var app = express(); app.get( '/' , function (req,res,next) { superagent.get( 'https://cnodejs.org/' ) .end( function (err,sres) { if (err){ return next(err); } // sres.text 里面存储着网页的 html 内容,将它传给 cheerio.load 之后 // 就可以得到一个实现了 jquery 接口的变量,我们习惯性地将它命名为 `$` // 剩下就都是

Cannot Basic Auth from React App with Axios or SuperAgent

混江龙づ霸主 提交于 2019-12-05 10:45:29
I try to make a GET request with axios and I always get 401. This happens only when I send the request from my react app. axios.get('http://localhost:8080/vehicles', { withCredentials: true, auth: { username: 'admin', password: 'admin' }, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, }) Postman GET request with the same credentials and Basic Auth set, works. If I simply type in my browser the url, a login box appears and with the same credentials, it works, I get what I want. I tried with SuperAgent too: Request.get("http://localhost:8080/vehicles")

Promises es6 and superagent

☆樱花仙子☆ 提交于 2019-12-04 18:30:27
问题 I'm attempting to use es6 promises with superagent. I'm attempting to call a function that has a superagent request wrapped inside. Request.post(buildReq).then(res => { if (res.ok) {//process res} }); Here is the function wrapping superagent static post(params) { superagent .post(params.url) .send(params.payload) .set('Accept', 'application/json') .end((error, res) => { return this.Promise.resolve(res); }) .bind(this); } I'm getting an error enter code here Uncaught TypeError: Cannot read

用node爬取网页上的内容

半城伤御伤魂 提交于 2019-12-03 23:41:54
如何用node简单的爬取网页上的内容: 1.安装express以及生成器 express官网: http://www.expressjs.com.cn/ npm install express --save npm install express-generator -g 2.用生成器创建新Express应用,进入项目并安装依赖包 express myapp cd myapp npm install 3.安装superagent superagent官网: http://visionmedia.github.io/superagent/ npm install superagent 4.安装cheerio cheerio官网: https://cheerio.js.org/ npm install cheerio 5.在routes文件夹下新建路由文件news.js var express = require("express"); const cheerio = require('cheerio'); const superagent = require('superagent'); var router = express.Router(); router.get('/', function (req, res, next) { // 抓取内容 superagent.get(