1. 安装依赖
  2. 引入依赖
  3. 发送请求
  4. 解析请求的返回值
  • 以下代码可以复制直接运行,获得 7 天的天气预报
const axios = require('axios')
const cheerio = require('cheerio') axios.get('http://www.weather.com.cn/weather/101280601.shtml')
.then(function (response) {
const $ = cheerio.load(response.data)
var data = [];
$('#7d li').each(function(){
var $this = $(this); // 使用trim去掉数据两端的空格
data.push({
title : trim($this.find('.sky h1').text()),
wea: trim($this.find('.sky .wea').text()),
leg: trim($this.find('.sky .tem').text())
});
}) function trim(str){
return str.replace(/(^\s*)|(\s*$)/g, "");
} console.log(data)
})
.catch(function (error) {
console.log(error);
});

使用 nodejs 和 axios 以及 cherrio 爬取天气预报的更多相关文章

  1. 和风api爬取天气预报数据

    ''' 和风api爬取天气预报数据 目标:https://free-api.heweather.net/s6/weather/forecast?key=cc33b9a52d6e48de85247779 ...

  2. 基于nodejs模拟浏览器post请求爬取json数据

    今天想爬取某网站的后台传来的数据,中间遇到了很多阻碍,花了2个小时才请求到数据,所以我在此总结了一些经验. 首先,放上我所爬取的请求地址http://api.chuchujie.com/api/?v= ...

  3. nodejs 使用superagent+cheerio+eventproxy爬取豆瓣帖子

    //cnpm install superagent cheerio eventproxy fs pathvar superagent = require('superagent'); var chee ...

  4. 【nodejs 爬虫】使用 puppeteer 爬取链家房价信息

    使用 puppeteer 爬取链家房价信息 目录 使用 puppeteer 爬取链家房价信息 页面结构 爬虫库 pupeteer 库 实现 打开待爬页面 遍历区级页面 方法一 方法二 遍历街道页面 遍 ...

  5. nodejs实现网站数据的爬取

    // 引入https模块,由于我们爬取的网站采用的是https协议 const https = require('https'); // 引入cheerio模块,使用这个模块可以将爬取的网页源代码进行 ...

  6. Python爬取天气预报

    实现爬取一天的天气预报 非常简单的一个小爬虫,利用的也是基本的request.BeautifulSoup.re库,算是简单的上手一个小测试吧 from urllib.request import ur ...

  7. scrapy框架综合运用 爬取天气预报 + 定时任务

    爬取目标网站: http://www.weather.com.cn/ 具体区域天气地址: http://www.weather.com.cn/weather1d/101280601.shtm(深圳) ...

  8. 使用python爬取天气预报,[python入门案例]

    # 天气网余姚地区爬虫案例 import requests from lxml import etree class WeatherSpider: def __init__(self): self.u ...

  9. NodeJs简单七行爬虫--爬取自己Qzone的说说并存入数据库

    没有那么难的,嘿嘿,说起来呢其实挺简单的,或者不能叫爬虫,只需要将自己的数据加载到程序里再进行解析就可以了,如果说你的Qzone是向所有人开放的,那么就有一个JSONP的接口,这么说来就简单了,也就不 ...

随机推荐

  1. python-day17(正式学习)

    目录 包 一.什么是包? 二.为什么要有包? 三.如何用包? 3.1 模块和包 3.2 扩展模块功能 3.3 修改__init__.py文件 绝对导入和相对导入 注意事项 模块不来总结了,直接去htt ...

  2. 文件的三种打开方式及with管理文件上下文

    文件的三种打开方式及with管理文件上下文 一.文件的三种打开方式 1.1 只读 f = open(r'D:\pycharm\yjy\上海python学习\456.txt','r',encoding= ...

  3. Ubuntu下更新Pycharm时权限不够(PyCharm does not have write access to...)

    问题描述 更新Pycharm时,出现如下问题 PyCharm does not have write access to /usr/local/software/pycharm-2019.1.3. P ...

  4. HNUSTOJ-1512 奇怪的导弹(暴力)

    1512: 奇怪的导弹 时间限制: 3 Sec  内存限制: 32 MB提交: 31  解决: 13[提交][状态][讨论版] 题目描述 最近国际形势比较紧张,就拿中国来说,比如南海问题,钓鱼岛事件等 ...

  5. cs244a-Introduction to Computer Networking-Unit1

    Unit 1 学习目标: how an application use the Internet The structure of the Internet:The 4 layer model The ...

  6. Scala Option 从官方DOC解析

    Represents optional values. Instances of Option are either an instance of scala.Some or the object N ...

  7. Java语言利用Google的Thumbnailator处理图片

    导读:在Java中制作高质量的缩略图可能是一项相当困难的任务,或者图片质量高页面加载慢等等原因使需要对图片进行处理,但是又不想写太多的代码太麻烦去处理图片,那么就可以使用Thumbnailator—— ...

  8. 2019-11-29-dotnet-core-输出调试信息到-DebugView-软件

    title author date CreateTime categories dotnet core 输出调试信息到 DebugView 软件 lindexi 2019-11-29 10:14:3 ...

  9. http与tcp

    一.基本概念 1.TCP连接 手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可以使手机终端通过无线网络建立TCP连接.TCP协议可以对上层网络提供接口,使上层网络数据的传输建立在“无差别” ...

  10. 【学习】027 Dubbo

    Dubbo概述 Dubbo的背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. 单一应用架构 ...