爬取中国地震台网以及地震科学数据

选择爬取的是一年内的内容

使用的是sqlite数据库,增量更新使用的48小时的链接


import requests
import os
import sqlite3



# 一年内的地震数据
def glob_add(page):
    i = 1
    count=0
    while i < page:

        url = 'http://www.ceic.ac.cn/ajax/speedsearch?num=6&&page={}'.format(i)

        headers = {
   
            'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'}
        html = requests.get(url, headers=headers, timeout=10000)

        response = html.text
        # 去除首尾 ( )
        data = eval(response[1:-1])
        records = data['shuju']
        for result in records:
            did = result['id']
            on_time = result['O_TIME']
            m = result['M']
            epi_lat = result['EPI_LAT']
            epi_lon = result['EPI_LON']
            epi_depth = result['EPI_DEPTH']
            location_c = result['LOCATION_C']
            count += 1
            print (count)
            cursor.execute(
                r"insert into earthquake values ({},{},'{}',{},{},{},{},'{}');".format(count,did, on_time, m, epi_lat, epi_lon,
                                                                                    epi_depth, location_c))

        i = i + 1

    conn.commit()


# 增量添加

def local_add():
    url = 'http://www.ceic.ac.cn/ajax/speedsearch?num=2&&page=1&&'
    headers = {
   
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'}
    html = requests.get(url, headers=headers, timeout=10000)
    response = html.text
    # 去除首尾 ( )
    data = eval(response[1:-1])
    records = data['shuju']
    count=0
    for result in records:
        did = result['id']
        on_time = result['O_TIME']
        m = result['M']
        epi_lat =
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值