[{"data":1,"prerenderedAt":64},["ShallowReactive",2],{"article-73":3},{"code":4,"msg":5,"data":6,"count":14},200,"查询成功",{"id":7,"title":8,"keywords":9,"description":10,"category_id":11,"content":12,"body_html":13,"thumb_up":14,"clicks":15,"sort":14,"remark":16,"status":17,"is_open":17,"is_deleted":14,"is_top":14,"is_recommend":14,"create_time":18,"update_time":19,"image_id":20,"url":13,"member_id":14,"cate_name":21,"prev":22,"next":25,"tags":28,"words":34,"read_time":35,"comments":36,"cover":37,"relevant":38},73,"城市天气爬去并绘制图表","python","以爬去深圳城市七天天气为例，`BeautifulSoup`爬去天气数据，`echart`绘制最高气温与最低气温折线图。",5,"\n以爬去深圳城市七天天气为例，`BeautifulSoup`爬去天气数据，`echart`绘制最高气温与最低气温折线图。\n\n###### 1、目标网站\n\n```bash\nhttps:\u002F\u002Fwww.tianqi.com\u002Fshenzhen\u002F\n```\n\n###### 2、依赖库\n\n```python\nimport requests\nfrom bs4 import BeautifulSoup\nfrom pyecharts.charts import Line\nfrom pyecharts import options\n```\n\n###### 3、完整代码\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python\n# -*- encoding: utf-8 -*-\n'''\n@File    :   WeatherSpider.py\n@Time    :   2020\u002F01\u002F02 20:18:47\n@Author  :   MrYong \n@Version :   1.0\n@Contact :   m.yong@foxmail.com\n@License :   (C)Copyright 2018-2019, MR YONG\n@Desc    :   城市天气爬去并绘制图表\n'''\n\n# here put the import lib\nimport requests\nfrom bs4 import BeautifulSoup\nfrom pyecharts.charts import Line\nfrom pyecharts import options\n\nclass WeatherSpider(object):\n    def __init__(self):\n        self.headers = {\n            'User-Agent': 'Mozilla\u002F5.0 (Windows NT 10.0; WOW64) AppleWebKit\u002F537.36 (KHTML, like Gecko) Chrome\u002F63.0.3239.132 Safari\u002F537.36'\n        }\n        self.proxies = {\n            'http':'http:\u002F\u002Fweb-proxy.tencent.com:8080\u002F',\n            'https':'http:\u002F\u002Fweb-proxy.tencent.com:8080\u002F'\n        }\n        self.url = 'https:\u002F\u002Fwww.tianqi.com\u002Fshenzhen\u002F'\n    def run(self):\n        page = self.getPage()\n        data = self.parse(page)\n        self.draw(data)\n    \n    def draw(self, data):\n        attr = data['week']\n        chart = Line()\n        chart.set_global_opts(title_opts=options.TitleOpts(title=\"深圳一周温度趋势\"))\n        chart.add_xaxis(attr)\n        chart.add_yaxis('最高气温', data['high'])\n        chart.add_yaxis('最低气温', data['low'])\n\n        chart.render('深圳天气.html')\n\n    def parse(self, html):\n        soup = BeautifulSoup(html, 'lxml')\n        time_html = soup.select('ul.week li')\n        #print(time_html)\n        week_list = []\n        date_list = []\n        #解析时间轴\n        for item in time_html:\n            date = item.select('li b')[0].get_text()\n            week = item.select('li span')[0].get_text()\n            week_list.append(week)\n            date_list.append(date)\n            #print(week)\n        #解析最高最低气温\n        temp  = soup.select('.zxt_shuju ul li')\n        high_temp = []\n        low_temp = []\n        for item in temp:\n            high = item.select('li span')[0].get_text()\n            low  = item.select('li b')[0].get_text()\n            high_temp.append(high)\n            low_temp.append(low)\n        \n        res = {\n            'week':week_list,\n            'date':date_list,\n            'high':high_temp,\n            'low':low_temp\n        }\n        return res\n    def getPage(self):\n        response = requests.get(self.url, headers=self.headers, proxies=self.proxies)\n        text = response.content.decode('utf-8')\n        return text\n\nws = WeatherSpider();\nws.run()\n\n```\n",null,0,579,"",1,"2020-01-03 16:20:15","2026-04-19 15:08:05",135,"Python",{"id":23,"title":24},72,"LeetCode之整数反转",{"id":26,"title":27},74,"超过经理收入的员工",[29,31],{"id":30,"name":21},27,{"id":32,"name":33},51,"爬虫",1499,3,2,"https:\u002F\u002Ftp.myong.top\u002Fstorage\u002Farticle\u002Fc5\u002F22a0e715e916985d7738d131d3b31b.jpg",[39,44,49,54,59],{"id":40,"title":41,"create_time":42,"description":43},95,"Django启用memcache缓存","2020-10-23 11:17:27","在动态网站中,用户所有的请求,服务器都会去数据库中进行相应的增,删,查,改,渲染模板,执行业务逻辑,最后生成用户看到的页面.当一个网站的用户访问量很大的时候,每一次的的后台操作,都会消耗很多的服务端资源,所以必须使用缓存来减轻后端服务器的压力.",{"id":45,"title":46,"create_time":47,"description":48},91,"用Python实现编程语言 20 年的动态排行榜","2020-06-24 16:06:54","爬取一下，自2001年5月至今，TIOBE 编程语言排行榜上编程语言的变化情况，看一下在接近20年的时间里，编程语言的热度是如何变化的。\r\n",{"id":50,"title":51,"create_time":52,"description":53},100,"re正则表达式","2021-07-10 18:09:52","正则表达式是一个特殊的字符序列，它能帮助你方便的检查一个字符串是否与某种模式匹配，本文罗列re正则表达式中，常用的匹配符号。",{"id":55,"title":56,"create_time":57,"description":58},34,"Python基础整理之列表常见操作","2019-02-10 16:53:55","列表是最常用的Python数据类型，它可以作为一个方括号内的逗号分隔值出现。列表的数据项不需要具有相同的类型",{"id":60,"title":61,"create_time":62,"description":63},63,"Python与mysqldump的数据库备份","2019-10-14 15:35:33","mysqldump是备份MySQL数据库的一种好工具。它相对于用phpmyadmin等备份工具更加快速，又避免受php.ini等的限制，在windows系统下还可以结合计划任务实现定时远程备份数据库",1783431661016]