当前位置: 首页 > article >正文

台风路径1-通过python3.7.0获取台风路径历史轨迹点数据并插入到postgresql数据库中

1.爬取页面 http://typhoon.zjwater.gov.cn/default.aspx

F12 找到对应存储历史轨迹点的url.

2.通过python爬取数据并插入到postgresql数据库中。

import requests
import json
import  psycopg2
import cx_Oracleurl = "http://typhoon.zjwater.gov.cn/Api/TyphoonInfo/201911?callback=jQuery1830020370286197575638_1566524188610&_=1566524188868"req_header = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36" ,"Referer": "http://typhoon.zjwater.gov.cn/default.aspx"}
r = requests.get(url, headers=req_header)
content_str = r.text[44:-3]
content_json = json.loads(content_str) #将字符串转为json对象
# print(content_json)
centerlat = content_json["centerlat"]
centerlng = content_json["centerlng"]
endtime = content_json["endtime"]
name = content_json["name"]
db = psycopg2.connect(database="postgis", user="postgres", password="postgres", host="127.0.0.1", port="5432")
print("已连接数据库")
cursor = db.cursor()
sql_del = "delete  from typhoon"
cursor.execute(sql_del)
db.commit()
for point in content_json["points"]:lat = point["lat"]#纬度lng = point["lng"]#经度movedirection = point["movedirection"]#移向movespeed = point["movespeed"]#移速power = point["power"]#风力值pressure = point["pressure"]#中心气压speed = point["speed"]  #风速strong = point["strong"]#风力文本# 使用 cursor() 方法创建一个游标对象 cursorsql_insert = "insert into typhoon (centerlat,centerlng,name,lng,lat,movedirection,movespeed,power,pressure,speed,strong) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"params = (centerlat, centerlng, name, lng, lat, movedirection, movespeed, power, pressure, speed, strong)# 使用 execute()  方法执行 SQL 查询cursor.execute(sql_insert, params)db.commit()
print("数据插入成功")

3.最后数据

http://www.lryc.cn/news/2417444.html

相关文章:

  • 基于51单片机智能饭店餐厅点菜机器WiFi无线设计19-385
  • vs安装包哪里有mfc_VS 2008和2010的MFC功能包
  • bash破壳漏洞分析(二)
  • 织梦模板使用方法-安装教程
  • 信息安全系统和安全体系
  • kindle电子书和新闻推送及RSS资源…
  • pci-pcie总线序号分配
  • 安装Red Hat 8Linux操作系统
  • 突破MAC地址过滤连接网络
  • 如何使用W5300实现ADSL连接(一)
  • 基于AD7705的32路AD采集
  • Windows动态桌面原理
  • 旗胜限价房让我深刻体会到我很傻很天真
  • crash调试linux dump信息
  • UT AUSTINVILLA 3D
  • 主板维修从入门到精通
  • activity启动模式应用,如FLAG_ACTIVITY_CLEAR_TOP
  • 分支语句——switch-case
  • 毕业论文中的图表目录
  • 单片机定时器中断(之中断概念)
  • 使用nlite制作集成驱动windows安装光盘及实践心得
  • 关于sqlserver中SqlParameter的用法注意事项
  • ccbp 知识点
  • 服务器出现大量 TIME_WAIT,如何解决
  • JavaSE:实现象棋游戏
  • 古典密码(部分合集)
  • VC6.0常见错误之::Debug Assertion Failed!
  • C#使用FileSystemWatcher来监控指定文件夹,并使用TCP/IP协议通过Socket发送到另外指定文件夹
  • 虚拟机Linux IP地址更改
  • 13 | 如何为团队设定合理的目标呢?