国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

爬蟲案例—雪球網(wǎng)行情中心板塊數(shù)據(jù)抓取

這篇具有很好參考價值的文章主要介紹了爬蟲案例—雪球網(wǎng)行情中心板塊數(shù)據(jù)抓取。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

爬蟲案例—雪球網(wǎng)行情中心板塊數(shù)據(jù)抓取

雪球網(wǎng)行情中心網(wǎng)址:https://xueqiu.com/hq

目標:市場一覽板塊、熱股榜板塊、新股預告板塊、關注排行榜板塊

import datetime

import requests

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

# 實例化session對象,進行會話保持
session = requests.Session()
url = 'https://xueqiu.com'
session.get(url, headers=headers)

# 時間戳轉成日期的函數(shù)
def timestamp_to_date(timestamp_data):
    timestamp = timestamp_data
    # 使用datetime.fromtimestamp()方法將時間戳轉換為datetime對象
    datetime_obj = datetime.datetime.fromtimestamp(timestamp)
    # 使用strftime()方法將datetime對象格式化為字符串表示的日期
    formatted_date = datetime_obj.strftime("%Y-%m-%d")
    return formatted_date


# 獲取四大板塊的指數(shù)
def get_four_index():
    url = 'https://stock.xueqiu.com/v5/stock/batch/quote.json?symbol=SH000001,SZ399001,SZ399006,SH000688'
    res = session.get(url, headers=headers)
    items_lst = res.json()['data']['items']
    print('市 場 一 覽:')
    print()
    print('板塊名稱\t指 數(shù)\t漲跌幅\t\t\t總市值')
    for item in items_lst:
        data_dic = item['quote']

        print(data_dic['name'], data_dic['current'], str(data_dic['chg']) + '(' + str(data_dic['percent']) + ')\t\t',
              f"{data_dic['market_capital'] / 1000000000000: >.2f}萬億")
    print('- ' * 50)


def get_stock(url_dict):
    for stock_type in url_lst_dict.keys():
        res = session.get(url_dict[stock_type], headers=headers)
        res.encoding = res.apparent_encoding

        stock_data = res.json()
        print(f'熱股榜——{stock_type}:\n')
        print('股票代碼\t\t', '股票名稱\t\t\t\t\t', '股票漲跌幅')
        for stock in stock_data['data']['items']:
            print(f'{stock["code"]:8}\t', f'{stock["name"]:<25}', f'{stock["percent"]:>8}')

        print('- ' * 30)


# 定義獲取新股json函數(shù)
def get_json(new_stock_url):
    res = session.get(new_stock_url, headers=headers)
    new_stock = res.json()
    return new_stock


# 定義獲取港股新股函數(shù)
def hk_new_stokc(hk_new_stock_url):
    new_stock = get_json(hk_new_stock_url)
    print('- ' * 40)
    print('港股')

    print('新股代碼\t', '新股名稱\t', '上市日期\t', '招股價下限\t', '招股價上限')
    new_stock_info = new_stock['data']['items']

    for new_stock_item in new_stock_info:
        # 上市日期時間戳
        list_timestamp = new_stock_item['list_date'] / 1000
        print(new_stock_item['symbol'], '\t', new_stock_item['name'], '\t', timestamp_to_date(list_timestamp), '\t',
              new_stock_item['issprice_min'], '\t', new_stock_item['issprice_max'])


# 定義滬深新股抓取函數(shù)
def hs_new_stock(hs_new_stock_url):
    new_stock = get_json(hs_new_stock_url)
    print('新 股 預 告')
    print('- ' * 40)
    print('滬深')
    print('新股發(fā)行數(shù)量:', new_stock['data']['count'])
    print('新股代碼\t', '新股名稱\t', '申購代碼\t', '預計發(fā)行量(萬股)\t', '申購上限(萬股)\t', '申購日期\t', '中簽號公布日')
    new_stock_info = new_stock['data']['items']

    for new_stock_item in new_stock_info:
        # 申購日期時間戳
        distr_timestamp = new_stock_item['onl_distr_date'] / 1000

        # 公布中簽日期時間戳
        draw_timestamp = new_stock_item['onl_lotwiner_stpub_date'] / 1000
        print(new_stock_item['symbol'], new_stock_item['name'], '\t', new_stock_item['onl_subcode'], '\t',
              new_stock_item['actissqty'], '\t\t\t', new_stock_item['onl_sub_maxqty'], '\t\t',
              timestamp_to_date(distr_timestamp), '\t', timestamp_to_date(draw_timestamp))


# 定義美股新股抓取函數(shù)
def un_new_stock(un_new_stock_url):
    new_stock = get_json(un_new_stock_url)
    print('- ' * 50)
    print('美股')
    print('新股發(fā)行數(shù)量:', new_stock['data']['count'])
    print('新股代碼\t', '新股名稱\t', '上市日期\t', '\t股本', '\t招股價下限\t', '招股價上限')
    new_stock_info = new_stock['data']['items']

    for new_stock_item in new_stock_info:
        # 上市日期時間戳
        list_timestamp = new_stock_item['list_date'] / 1000
        if new_stock_item['shares']:
            new_shares = '\t' + str(new_stock_item['shares'] / 10000) + '萬'
        else:
            new_shares = '\t\t-\t'

        if new_stock_item['issprice_min']:
            new_min = '\t' + str(new_stock_item['issprice_min']) + '\t'

        if new_stock_item['issprice_max']:
            new_max = '\t' + str(new_stock_item['issprice_max']) + '\t'

        else:
            new_max = '\t-'
            new_min = '\t-\t'

        print(new_stock_item['symbol'], '\t', new_stock_item['name'][:8], '\t', timestamp_to_date(list_timestamp),
              new_shares, new_min, new_max)


# 本周排行榜, 本周新增股票,最熱門股票
def get_new_add_stock(new_add_url):
    new_add_stock = get_json(new_add_url)
    print('- ' * 50)
    print('關注排行榜——本周新增')
    new_list = new_add_stock['data']['list']
    print('股票名稱\t\t股 價\t\t關 注')
    for add_stock in new_list:
        print(f"{add_stock['name']}\t\t{add_stock['current']}\t\t{int(add_stock['follow7d']):<}")


# 本周排行榜,最熱門股票
def get_hot_stock(new_hot_url):
    hot_stock = get_json(new_hot_url)
    print('- ' * 50)
    print('關注排行榜——最熱門')
    hot_lst = hot_stock['data']['list']
    print('股票名稱\t\t股 價\t\t關 注')
    for hot_stock in hot_lst:
        print(f"{hot_stock['name']}\t\t{hot_stock['current']}\t\t{int(hot_stock['follow']):<}")


if __name__ == '__main__':
    # 四大板塊信息
    get_four_index()

    # 熱門股票
    url_lst_dict = {'滬深': 'https://stock.xueqiu.com/v5/stock/hot_stock/list.json?page=1&size=9&_type=12&type=12',
                    '港股': 'https://stock.xueqiu.com/v5/stock/hot_stock/list.json?page=1&size=9&_type=13&type=13',
                    '美股': 'https://stock.xueqiu.com/v5/stock/hot_stock/list.json?page=1&size=9&_type=11&type=11'}
    get_stock(url_lst_dict)

    print()
    # 滬深新股網(wǎng)址
    hs_new_stock_url = 'https://stock.xueqiu.com/v5/stock/preipo/cn/query.json?type=subscribe&order_by=onl_subbeg_date&order=asc&source=new_subscribe&page=1&size=10'
    hs_new_stock(hs_new_stock_url)
    # 港股新股網(wǎng)址
    hk_new_stock_url = 'https://stock.xueqiu.com/v5/stock/preipo/hk/query.json?order=desc&order_by=list_date&type=unlisted&page=1&size=10'
    hk_new_stokc(hk_new_stock_url)

    # 美股新股網(wǎng)址
    un_new_stock_url = 'https://stock.xueqiu.com/v5/stock/preipo/us/list.json?order=desc&order_by=list_date&type=unlisted&page=1&size=10'
    un_new_stock(un_new_stock_url)

    # 關注排行榜,本周新增
    new_add_stock_url = 'https://stock.xueqiu.com/v5/stock/screener/screen.json?page=1&only_count=0&size=10&category=CN&order_by=follow7d&order=desc'
    get_new_add_stock(new_add_stock_url)

    # 最熱門股票
    hot_stock_url = 'https://stock.xueqiu.com/v5/stock/screener/screen.json?page=1&only_count=0&size=10&category=CN&order_by=follow&order=desc'
    get_hot_stock(hot_stock_url)

運行結果如下:

爬蟲案例—雪球網(wǎng)行情中心板塊數(shù)據(jù)抓取,爬蟲案例,編程,筆記,爬蟲,python

爬蟲案例—雪球網(wǎng)行情中心板塊數(shù)據(jù)抓取,爬蟲案例,編程,筆記,爬蟲,python

爬蟲案例—雪球網(wǎng)行情中心板塊數(shù)據(jù)抓取,爬蟲案例,編程,筆記,爬蟲,python文章來源地址http://www.zghlxwxcb.cn/news/detail-803267.html

到了這里,關于爬蟲案例—雪球網(wǎng)行情中心板塊數(shù)據(jù)抓取的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • 爬蟲案例—爬取ChinaUnix.net論壇板塊標題

    爬蟲案例—爬取ChinaUnix.net論壇板塊標題

    ChinaUnix.net論壇網(wǎng)址:http://bbs.chinaunix.net 目標:抓取各個板塊的標題和內(nèi)容的標題 網(wǎng)站截圖: 利用requests和xpath實現(xiàn)目標。源碼如下: 運行結果如下:

    2024年01月19日
    瀏覽(20)
  • 使用分布式HTTP代理爬蟲實現(xiàn)數(shù)據(jù)抓取與分析的案例研究

    使用分布式HTTP代理爬蟲實現(xiàn)數(shù)據(jù)抓取與分析的案例研究

    在當今信息爆炸的時代,數(shù)據(jù)已經(jīng)成為企業(yè)決策和發(fā)展的核心資源。然而,要獲取大規(guī)模的數(shù)據(jù)并進行有效的分析是一項艱巨的任務。為了解決這一難題,我們進行了一項案例研究,通過使用分布式HTTP代理爬蟲,實現(xiàn)數(shù)據(jù)抓取與分析的有效整合。本文旨在分享我們的研究成果

    2024年02月15日
    瀏覽(34)
  • Day:004(1) | Python爬蟲:高效數(shù)據(jù)抓取的編程技術(數(shù)據(jù)解析)

    Day:004(1) | Python爬蟲:高效數(shù)據(jù)抓取的編程技術(數(shù)據(jù)解析)

    數(shù)據(jù)解析-正則表達式 在前面我們已經(jīng)搞定了怎樣獲取頁面的內(nèi)容,不過還差一步,這么多雜亂的代碼夾雜文字我們怎樣 把它提取出來整理呢?下面就開始介紹一個十分強大的工具,正則表達式! ????????正則表達式是對字符串操作的一種邏輯公式,就是用事先定義好的

    2024年04月12日
    瀏覽(18)
  • 35 | RESTful & Socket:行情數(shù)據(jù)對接和抓取

    35 | RESTful & Socket:行情數(shù)據(jù)對接和抓取

    上一節(jié),我們介紹了交易所的交易模式,數(shù)字貨幣交易所 RESTful 接口的常見概念,以及如何調(diào)用 RESTful 接口進行訂單操作。眾所周知,買賣操作的前提,是你需要已知市場的最新情況。這節(jié)課里,將介紹交易系統(tǒng)底層另一個最重要的部分,行情數(shù)據(jù)的對接和抓取。 行情數(shù)據(jù),

    2024年02月05日
    瀏覽(20)
  • 爬蟲案例—抓取小米商店應用

    代碼如下: # 抓取第一頁的內(nèi)容 import requests from lxml import etree url = ‘https://app.mi.com/catTopList/0?page=1’ headers = { ‘User-Agent’: ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36’ } res = requests.get(url, headers=headers) content = res.content.decode(‘

    2024年01月16日
    瀏覽(25)
  • 爬蟲案例—表情黨圖片data-src抓取

    爬蟲案例—表情黨圖片data-src抓取

    表情黨網(wǎng)址:https://qq.yh31.com 抓取心情板塊的圖片data-src 由于此頁面采用的是懶加載技術,為了節(jié)省網(wǎng)絡帶寬和減輕服務器壓力。不瀏覽的圖片,頁面不加載,統(tǒng)一顯示LOADING…。如下圖: 按F12(谷歌瀏覽器)通過分析,表情圖片的真正鏈接為data-src 通過分析,在搜索框里輸入

    2024年01月16日
    瀏覽(16)
  • 冠達管理:有色金屬迎順周期行情 板塊估值降至歷史低位

    冠達管理:有色金屬迎順周期行情 板塊估值降至歷史低位

    近期,A股地產(chǎn)鏈相繼迸發(fā),家居用品、房地產(chǎn)服務等細分板塊持續(xù)反彈。沉寂多時的地產(chǎn)鏈上游——有色金屬板塊相同遭到資金青睞。證券時報·數(shù)據(jù)寶統(tǒng)計,8月28日以來,有色金屬指數(shù)累計上漲近6%,跑贏同期上證指數(shù)。 從個股來看,有色金屬股票8月28日以來平均上漲5.4

    2024年02月10日
    瀏覽(18)
  • 爬蟲數(shù)據(jù)抓取怎么弄?

    爬蟲數(shù)據(jù)抓取是一種自動化的數(shù)據(jù)采集技術,可以快速、高效地從互聯(lián)網(wǎng)上獲取大量的數(shù)據(jù)。本文將介紹爬蟲數(shù)據(jù)抓取的基本原理、常用的爬蟲框架和工具、爬蟲數(shù)據(jù)抓取的注意事項以及爬蟲數(shù)據(jù)抓取的應用場景。 一、爬蟲數(shù)據(jù)抓取的基本原理 爬蟲數(shù)據(jù)抓取的基本原理是通

    2024年02月05日
    瀏覽(19)
  • 逆向爬蟲進階實戰(zhàn):突破反爬蟲機制,實現(xiàn)數(shù)據(jù)抓取

    逆向爬蟲進階實戰(zhàn):突破反爬蟲機制,實現(xiàn)數(shù)據(jù)抓取

    隨著網(wǎng)絡技術的發(fā)展,網(wǎng)站為了保護自己的數(shù)據(jù)和資源,紛紛采用了各種反爬蟲機制。然而,逆向爬蟲技術的出現(xiàn),使得我們可以突破這些限制,實現(xiàn)對目標網(wǎng)站的深入分析和抓取。本文將介紹逆向爬蟲進階實戰(zhàn)的一些技巧和代碼片段,幫助讀者更好地理解和掌握這一技術。

    2024年02月04日
    瀏覽(21)
  • 高并發(fā)數(shù)據(jù)抓取實戰(zhàn):使用HTTP爬蟲ip提升抓取速度

    高并發(fā)數(shù)據(jù)抓取實戰(zhàn):使用HTTP爬蟲ip提升抓取速度

    又到每天一期學習爬蟲的時間了,作為一名專業(yè)的爬蟲程序員,今天要跟你們分享一個超實用的技巧,就是利用HTTP爬蟲ip來提升高并發(fā)數(shù)據(jù)抓取的速度。聽起來有點高大上?別擔心,我會用通俗易懂的話來和你們說,讓你們秒懂怎么操作的。 首先,咱們得理解一下為什么HT

    2024年02月11日
    瀏覽(23)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包