[Node.js]27. Level 5: URL Building & Doing the Request
Let's create a page which calls the twitter search API and displays the last few results for Code School. The first step is to construct the proper URL, which is all you need to do in this challenge.
Complete the URL options which will be sent into the the url
module's format method. The URL you'll want to construct is the following:
http://search.twitter.com/search.json?q=codeschool
var url = require('url'); options = {
// add URL options here
protocol: "http",
host: 'search.twitter.com',
pathname: '/search.json',
query: {q: "codeschool"}
}; var searchURL = url.format(options);
console.log(searchURL);
Next we'll need to include the request module, use that to do a simple web request, and print the returned JSON out to the console. You'll want to check out this example in the readme.
var url = require('url');
var request = require('request'); options = {
protocol: "http:",
host: "search.twitter.com",
pathname: '/search.json',
query: { q: "codeschool"}
}; var searchURL = url.format(options);
request(searchURL, function(err, res, body){
if (!err && res.statusCode == 200) {
console.log(body) // Print the google web page.
}
});
[Node.js]27. Level 5: URL Building & Doing the Request的更多相关文章
- node.js基础 1之 URL网址解析的好帮手
URL和URI的区别: URL是统一资源定位符 URI是统一资源标识符 URL是URI的子集(URL一定是URI,但URI不一定是URL) node中的URL中的url.parse protocol: ...
- node.js HTTP模块、URL 模块
在浏览器输入存在的网址的一个交互过程 1.用户通过浏览器发送一个http的请求到指定的主机 2.服务器接收到该请求,对该请求进行分析和处理 3.服务器处理完成以后,返回对应的数据到用户机器 4.浏览器 ...
- 极简 Node.js 入门 - 5.2 url & querystring
极简 Node.js 入门系列教程:https://www.yuque.com/sunluyong/node 本文更佳阅读体验:https://www.yuque.com/sunluyong/node ...
- Node.js:path、url、querystring模块
Path模块 该模块提供了对文件或目录路径处理的方法,使用require('path')引用. 1.获取文件路径最后部分basename 使用basename(path[,ext])方法来获取路径的最 ...
- [Node.js]29. Level 6: Socket.io: Setting up Socket.io server-side & Client socket.io setup
Below we've already created an express server, but we want to start building a real-time Q&A mod ...
- [Node.js]24. Level 5: Express, Express routes
Create an express route that responds to GET requests at the URL /tweets that responds with the file ...
- [Node.js]31. Level 7: Redis coming for Node.js, Simple Redis Commands
Let's start practicing using the redis key-value store from our node application. First require the ...
- [Node.js]30. Level 6: Listen 'Question' from client, and then Answer the Question
Clients can also answer each other questions, so let's build that feature by first listening for the ...
- [Node.js]28. Level 5: Express Server
Now let's create an express server which queries out for this search term and just returns the json. ...
随机推荐
- BZOJ 4289: PA2012 Tax 差分建图 最短路
https://www.lydsy.com/JudgeOnline/problem.php?id=4289 https://www.cnblogs.com/clrs97/p/5046933.html ...
- hdu 5288 OO’s Sequence(2015多校第一场第1题)枚举因子
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 题意:在闭区间[l,r]内有一个数a[i],a[i]不能整除 除去自身以外的其他的数,f(l,r ...
- JAVA基础(一) ——— static 关键字
1. 静态代码块 保证只创建一次,提升属性的级别为类变量.初始化后独自占用一块内存 2. 静态代码块执行触发条件 (1).当创建这个类的实例 (2).当调用这个类的静态变量 (3).当调用这个类的 ...
- bzoj 2961
根据“点在圆内”关系,列出点P(x0,y0)在圆C(x,y)内的关系: (x-x0)^2+(y-y0)^2 <= x^2+y^2 化简得: 2*x0*x+2*y0*y >= x0^2+y0 ...
- 【BZOJ-1194】潘多拉的盒子 拓扑排序 + DP
1194: [HNOI2006]潘多拉的盒子 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 456 Solved: 215[Submit][Stat ...
- Codeforces Round #294 (Div. 2)A - A and B and Chess 水题
A. A and B and Chess time limit per test 1 second memory limit per test 256 megabytes input standard ...
- TensorFlow安装和HelloWorld
TensorFlow安装 TensorFlow可以在各种操作系统上面安装.安装的时候要注意TensorFlow的类型,一种是普通的版本,仅支持CPU,安装简单.另外一种类型带GPU的,可以利用GPU来 ...
- Maven的POM文件parent节点不可以使用properties里面的变量
Maven的POM文件parent节点不可以使用properties里面的变量 但是如果在子项目上的parent节点是可以使用父项目里定义的properties变量 如果一开始为单项目,或者最顶层项目 ...
- hdu 2112 HDU Today (floyd算法)
这道题貌似在原来学长给我们的搞的小比赛中出过! 这次又让我遇到,果断拿下! 不过方法很蠢,跑了1000多ms,虽然要求5000ms以内! 题目就是给你一些位置之间的距离,然后再让你求特定的两点之间的距 ...
- 【scrapy】使用方法概要(四)(转)
[请初学者作为参考,不建议高手看这个浪费时间] 上一篇文章,我们抓取到了一大批代理ip,本篇文章介绍如何实现downloaderMiddleware,达到随即使用代理ip对目标网站进行抓取的. 抓取的 ...