iT邦幫忙

1

Day28 參加職訓(機器學習與資料分析工程師培訓班),網站設計與網頁工程技術

  • 分享至 

  • xImage
  •  

今日練習爬蟲,將爬下來的資料傳到資料庫(今日時間不夠,下次上課再進行)

BTC價格

import requests
from bs4 import BeautifulSoup
import json
import datetime

#target_url = 'https://coinmarketcap.com/currencies/bitcoin/historical-data/'
start_time = '1628006400'
end_time = '1628236123'
target_api = 'https://api.coinmarketcap.com/data-api/v3/cryptocurrency/historical?id=1&convertId=2781&timeStart='+ start_time +'&timeEnd='+end_time

#headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'}

data = requests.get( target_api , headers = headers)
json_data = json.loads(data.text)
time = json_data['data']['quotes'][0]['timeOpen']
price = json_data['data']['quotes'][0]['quote']['open']

data_btc = json_data['data']['quotes']
for price in data_btc:
    print (price['timeOpen'])
    print ( price['quote']['open'])

2021-08-04T00:00:00.000Z
38213.33196989
2021-08-05T00:00:00.000Z
39744.51415501


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言