主頁 > 後端開發 > 教你Python3實作12306火車票自動搶票,小白必學

教你Python3實作12306火車票自動搶票,小白必學

2020-10-02 20:31:01 後端開發

最近在學Python,所以用Python寫了這個12306搶票腳本,分享出來,與大家共同交流和學習,有不對的地方,請大家多多指正,話不多說,進入正題:在進入正題之前,我想說明一下,由于12306官網的改版更新,所以腳本作了一點小小的變化,具體修改后的原始碼,可以到GitHub上面查看……新版腳本原始碼


另外要注意:
不管你是為了Python就業還是興趣愛好,記住:專案開發經驗永遠是核心,如果你沒有2020最新python入門到高級實戰視頻教程,可以去小編的Python交流.裙 :七衣衣九七七巴而五(數字的諧音)轉換下可以找到了,里面很多新python教程專案,還可以跟老司機交流討教!

這個腳本目前只能刷一趟車的,人數可以是多個,支持選取作為型別等,
實作思路是splinter.browser模擬瀏覽器登陸和操作,由于12306的驗證碼不好自動識別,所以,驗證碼需要用戶進行手動識別,并進行登陸操作,之后的事情,就交由腳本來操作就可以了,下面是我測驗時候的一些截圖:

第一步:如下圖,首先輸入搶票基本資訊

第二步:然后進入登錄頁,需要手動輸入驗證碼,并點擊登陸操作

第三步:登陸后,自動進入到搶票頁面,如下圖這樣的

最后:就是坐等刷票結果就好了,如下圖這樣,就說是刷票成功了,刷到票后,會進行短信和郵件的通知,請記得及時前往12306進行支付,不然就白搶了,

Python運行環境:python3.6
用到的模塊:re、splinter、time、sys、httplib2、urllib、smtplib、email
未安裝的模塊,請使用pip instatll進行安裝,例如:pip install splinter
如下代碼是這個腳本所有用到的模塊引入:

 

 

 

import re
from splinter.browser import Browser
from time import sleep
import sys
import httplib2
from urllib import parse
import smtplib
from email.mime.text import MIMEText
復制代碼

 

刷票前資訊準備,我主要說一下始發站和目的地的cookie值獲取,因為輸入城市的時候,需要通過cookie值,cookie值可以通過12306官網,然后在F12(相信所有的coder都知道這個吧)的network里面的查詢請求cookie中可以看到,在請求的header里面可以找到,_jc_save_fromStation值是出發站的cookie,_jc_save_toStation的值是目的地的cookie,然后加入到代碼里的城市的cookie字典city_list里即可,鍵是城市的首字母,值是cookie值的形式,

搶票,肯定需要先登錄,我這里模擬的登錄操作,會自動填充12306的賬號名和密碼,當然,你也可以在打開的瀏覽器中修改賬號和密碼,實作的關鍵代碼如下:

 

 

 

def do_login(self):
    """登錄功能實作,手動識別驗證碼進行登錄"""
    self.driver.visit(self.login_url)
    sleep(1)
    self.driver.fill('loginUserDTO.user_name', self.user_name)
    self.driver.fill('userDTO.password', self.password)
    print('請輸入驗證碼……')
    while True:
        if self.driver.url != self.init_my_url:
            sleep(1)
        else:
            break
復制代碼

 

登錄之后,就是控制刷票的各種操作處理了,這里,我就不貼代碼了,因為代碼比較多,別擔心,在最后,我會貼出完整的代碼的,

當刷票成功后,我會進行短信和郵件的雙重通知,當然,這里短信通知的平臺,就看你用那個具體來修改代碼了,我用的是互億無線的體驗版的免費短信通知介面;發送郵件模塊我用的是smtplib,發送郵件服務器用的是163郵箱,如果用163郵箱的話,你還沒有設定客戶端授權密碼,記得先設定客戶端授權密碼就好了,挺方便的,以下是主要實作代碼:

 

 

 

def send_sms(self, mobile, sms_info):
    """發送手機通知短信,用的是-互億無線-的測驗短信"""
    host = "106.ihuyi.com"
    sms_send_uri = "/webservice/sms.php?method=Submit"
    account = "C59782899"
    pass_word = "19d4d9c0796532c7328e8b82e2812655"
    params = parse.urlencode(
        {'account': account, 'password': pass_word, 'content': sms_info, 'mobile': mobile, 'format': 'json'}
    )
    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
    conn = httplib2.HTTPConnectionWithTimeout(host, port=80, timeout=30)
    conn.request("POST", sms_send_uri, params, headers)
    response = conn.getresponse()
    response_str = response.read()
    conn.close()
    return response_str

def send_mail(self, receiver_address, content):
    """發送郵件通知"""
    # 連接郵箱服務器資訊
    host = 'smtp.163.com'
    port = 25
    sender = '[email protected]'  # 你的發件郵箱號碼
    pwd = '******'  # 不是登陸密碼,是客戶端授權密碼
    # 發件資訊
    receiver = receiver_address
    body = '<h2>溫馨提醒:</h2><p>' + content + '</p>'
    msg = MIMEText(body, 'html', _charset="utf-8")
    msg['subject'] = '搶票成功通知!'
    msg['from'] = sender
    msg['to'] = receiver
    s = smtplib.SMTP(host, port)
    # 開始登陸郵箱,并發送郵件
    s.login(sender, pwd)
    s.sendmail(sender, receiver, msg.as_string())
復制代碼

 

說了那么多,感覺都是說了好多廢話啊,哈哈,不好意思,耽誤大家時間來看我瞎扯了,我貼上大家最關心的原始碼,請接碼,大家在嘗試運行程序中,有任何問題,可以給我留言或者私信我,我看到都會及時回復大家的:

 

 

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
通過splinter刷12306火車票
可以自動填充賬號密碼,同時,在登錄時,也可以修改賬號密碼
然后手動識別驗證碼,并登陸,接下來的事情,交由腳本來做了,靜靜的等待搶票結果就好(刷票程序中,瀏覽器不可關閉)
author: cuizy
time: 2018-05-30
"""

import re
from splinter.browser import Browser
from time import sleep
import sys
import httplib2
from urllib import parse
import smtplib
from email.mime.text import MIMEText


class BrushTicket(object):
    """買票類及實作方法"""

    def __init__(self, user_name, password, passengers, from_time, from_station, to_station, number, seat_type, receiver_mobile, receiver_email):
        """定義實體屬性,初始化"""
        # 1206賬號密碼
        self.user_name = user_name
        self.password = password
        # 乘客姓名
        self.passengers = passengers
        # 起始站和終點站
        self.from_station = from_station
        self.to_station = to_station
        # 乘車日期
        self.from_time = from_time
        # 車次編號
        self.number = number.capitalize()
        # 座位型別所在td位置
        if seat_type == '商務座特等座':
            seat_type_index = 1
            seat_type_value = https://www.cnblogs.com/chengxuyuanaa/p/9
        elif seat_type == '一等座':
            seat_type_index = 2
            seat_type_value = https://www.cnblogs.com/chengxuyuanaa/p/'M'
        elif seat_type == '二等座':
            seat_type_index = 3
            seat_type_value = https://www.cnblogs.com/chengxuyuanaa/p/0
        elif seat_type == '高級軟臥':
            seat_type_index = 4
            seat_type_value = https://www.cnblogs.com/chengxuyuanaa/p/6
        elif seat_type == '軟臥':
            seat_type_index = 5
            seat_type_value = https://www.cnblogs.com/chengxuyuanaa/p/4
        elif seat_type == '動臥':
            seat_type_index = 6
            seat_type_value = https://www.cnblogs.com/chengxuyuanaa/p/'F'
        elif seat_type == '硬臥':
            seat_type_index = 7
            seat_type_value = https://www.cnblogs.com/chengxuyuanaa/p/3
        elif seat_type == '軟座':
            seat_type_index = 8
            seat_type_value = https://www.cnblogs.com/chengxuyuanaa/p/2
        elif seat_type == '硬座':
            seat_type_index = 9
            seat_type_value = https://www.cnblogs.com/chengxuyuanaa/p/1
        elif seat_type == '無座':
            seat_type_index = 10
            seat_type_value = https://www.cnblogs.com/chengxuyuanaa/p/1
        elif seat_type == '其他':
            seat_type_index = 11
            seat_type_value = https://www.cnblogs.com/chengxuyuanaa/p/1
        else:
            seat_type_index = 7
            seat_type_value = https://www.cnblogs.com/chengxuyuanaa/p/3
        self.seat_type_index = seat_type_index
        self.seat_type_value = seat_type_value
        # 通知資訊
        self.receiver_mobile = receiver_mobile
        self.receiver_email = receiver_email
        # 主要頁面網址
        self.login_url = 'https://kyfw.12306.cn/otn/login/init'
        self.init_my_url = 'https://kyfw.12306.cn/otn/index/initMy12306'
        self.ticket_url = 'https://kyfw.12306.cn/otn/leftTicket/init'
        # 瀏覽器驅動資訊,驅動下載頁:https://sites.google.com/a/chromium.org/chromedriver/downloads
        self.driver_name = 'chrome'
        self.executable_path = 'C:\\Users\cuizy\AppData\Local\Programs\Python\Python36\Scripts\chromedriver.exe'

    def do_login(self):
        """登錄功能實作,手動識別驗證碼進行登錄"""
        self.driver.visit(self.login_url)
        sleep(1)
        self.driver.fill('loginUserDTO.user_name', self.user_name)
        self.driver.fill('userDTO.password', self.password)
        print('請輸入驗證碼……')
        while True:
            if self.driver.url != self.init_my_url:
                sleep(1)
            else:
                break

    def start_brush(self):
        """買票功能實作"""
        self.driver = Browser(driver_name=self.driver_name, executable_path=self.executable_path)
        # 瀏覽器視窗的大小
        self.driver.driver.set_window_size(900, 700)
        self.do_login()
        self.driver.visit(self.ticket_url)
        try:
            print('開始刷票……')
            # 加載車票查詢資訊
            self.driver.cookies.add({"_jc_save_fromStation": self.from_station})
            self.driver.cookies.add({"_jc_save_toStation": self.to_station})
            self.driver.cookies.add({"_jc_save_fromDate": self.from_time})
            self.driver.reload()
            count = 0
            while self.driver.url.split('?')[0] == self.ticket_url:
                self.driver.find_by_text('查詢').click()
                sleep(1)
                count += 1
                print('第%d次點擊查詢……' % count)
                try:
                    car_no_location = self.driver.find_by_id("queryLeftTable")[0].find_by_text(self.number)[1]
                    current_tr = car_no_location.find_by_xpath("./../../../../..")
                    if current_tr.find_by_tag('td')[self.seat_type_index].text == '--':
                        print('無此座位型別出售,已結束當前刷票,請重新開啟!')
                        sys.exit(1)
                    elif current_tr.find_by_tag('td')[self.seat_type_index].text == '無':
                        print('無票,繼續嘗試……')
                    else:
                        # 有票,嘗試預訂
                        print('刷到票了(余票數:' + str(current_tr.find_by_tag('td')[self.seat_type_index].text) + '),開始嘗試預訂……')
                        current_tr.find_by_css('td.no-br>a')[0].click()
                        sleep(1)
                        key_value = https://www.cnblogs.com/chengxuyuanaa/p/1
                        for p in self.passengers:
                            # 選擇用戶
                            print('開始選擇用戶……')
                            self.driver.find_by_text(p).last.click()
                            # 選擇座位型別
                            print('開始選擇席別……')
                            if self.seat_type_value != 0:
                                seat_select = self.driver.find_by_id("seatType_" + str(key_value))[0]
                                seat_select.find_by_xpath("//option[@value='" + str(self.seat_type_value) + "']")[0].click()
                            key_value += 1
                            sleep(0.5)
                            if p[-1] == ')':
                                self.driver.find_by_id('dialog_xsertcj_ok').click()
                        print('正在提交訂單……')
                        self.driver.find_by_id('submitOrder_id').click()
                        sleep(2)
                        # 查看放回結果是否正常
                        submit_false_info = self.driver.find_by_id('orderResultInfo_id')[0].text
                        if submit_false_info != '':
                            print(submit_false_info)
                            self.driver.find_by_id('qr_closeTranforDialog_id').click()
                            sleep(0.2)
                            self.driver.find_by_id('preStep_id').click()
                            sleep(0.3)
                            continue
                        print('正在確認訂單……')
                        self.driver.find_by_id('qr_submit_id').click()
                        print('預訂成功,請及時前往支付……')
                        # 發送通知資訊
                        self.send_mail(self.receiver_email, '恭喜您,搶到票了,請及時前往12306支付訂單!')
                        self.send_sms(self.receiver_mobile, '您的驗證碼是:8888,請不要把驗證碼泄露給其他人,')
                except Exception as error_info:
                    print(error_info)
        except Exception as error_info:
            print(error_info)

    def send_sms(self, mobile, sms_info):
        """發送手機通知短信,用的是-互億無線-的測驗短信"""
        host = "106.ihuyi.com"
        sms_send_uri = "/webservice/sms.php?method=Submit"
        account = "C59782899"
        pass_word = "19d4d9c0796532c7328e8b82e2812655"
        params = parse.urlencode(
            {'account': account, 'password': pass_word, 'content': sms_info, 'mobile': mobile, 'format': 'json'}
        )
        headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
        conn = httplib2.HTTPConnectionWithTimeout(host, port=80, timeout=30)
        conn.request("POST", sms_send_uri, params, headers)
        response = conn.getresponse()
        response_str = response.read()
        conn.close()
        return response_str

    def send_mail(self, receiver_address, content):
        """發送郵件通知"""
        # 連接郵箱服務器資訊
        host = 'smtp.163.com'
        port = 25
        sender = '******@163.com'  # 你的發件郵箱號碼
        pwd = '******'  # 不是登陸密碼,是客戶端授權密碼
        # 發件資訊
        receiver = receiver_address
        body = '<h2>溫馨提醒:</h2><p>' + content + '</p>'
        msg = MIMEText(body, 'html', _charset="utf-8")
        msg['subject'] = '搶票成功通知!'
        msg['from'] = sender
        msg['to'] = receiver
        s = smtplib.SMTP(host, port)
        # 開始登陸郵箱,并發送郵件
        s.login(sender, pwd)
        s.sendmail(sender, receiver, msg.as_string())


if __name__ == '__main__':
    # 12306用戶名
    user_name = input('請輸入12306用戶名:')
    while user_name == '':
        user_name = input('12306用戶名不能為空,請重新輸入:')
    # 12306登陸密碼
    password = input('請輸入12306登陸密碼:')
    while password == '':
        password = input('12306登陸密碼不能為空,請重新輸入:')
    # 乘客姓名
    passengers_input = input('請輸入乘車人姓名,多人用英文逗號“,”連接,(例如單人“張三”或者多人“張三,李四”):')
    passengers = passengers_input.split(",")
    while passengers_input == '' or len(passengers) > 4:
        print('乘車人最少1位,最多4位!')
        passengers_input = input('請重新輸入乘車人姓名,多人用英文逗號“,”連接,(例如單人“張三”或者多人“張三,李四”):')
        passengers = passengers_input.split(",")
    # 乘車日期
    from_time = input('請輸入乘車日期(例如“2018-08-08”):')
    date_pattern = re.compile(r'^\d{4}-\d{2}-\d{2}$')
    while from_time == '' or re.findall(date_pattern, from_time) == []:
        from_time = input('乘車日期不能為慷訓者時間格式不正確,請重新輸入:')
    # 城市cookie字典
    city_list = {
        'bj': '%u5317%u4EAC%2CBJP',  # 北京
        'hd': '%u5929%u6D25%2CTJP',  # 邯鄲
        'nn': '%u5357%u5B81%2CNNZ',  # 南寧
        'wh': '%u6B66%u6C49%2CWHN',  # 武漢
        'cs': '%u957F%u6C99%2CCSQ',  # 長沙
        'ty': '%u592A%u539F%2CTYV',  # 太原
        'yc': '%u8FD0%u57CE%2CYNV',  # 運城
        'gzn': '%u5E7F%u5DDE%u5357%2CIZQ',  # 廣州南
        'wzn': '%u68A7%u5DDE%u5357%2CWBZ',  # 梧州南
    }
    # 出發站
    from_input = input('請輸入出發站,只需要輸入首字母就行(例如北京“bj”):')
    while from_input not in city_list.keys():
        from_input = input('出發站不能為慷訓不支持當前出發站(如有需要,請聯系管理員!),請重新輸入:')
    from_station = city_list[from_input]
    # 終點站
    to_input = input('請輸入終點站,只需要輸入首字母就行(例如北京“bj”):')
    while to_input not in city_list.keys():
        to_input = input('終點站不能為慷訓不支持當前終點站(如有需要,請聯系管理員!),請重新輸入:')
    to_station = city_list[to_input]
    # 車次編號
    number = input('請輸入車次號(例如“G110”):')
    while number == '':
        number = input('車次號不能為空,請重新輸入:')
    # 座位型別
    seat_type = input('請輸入座位型別(例如“軟臥”):')
    while seat_type == '':
        seat_type = input('座位型別不能為空,請重新輸入:')
    # 搶票成功,通知該手機號碼
    receiver_mobile = input('請預留一個手機號碼,方便搶到票后進行通知(例如:18888888888):')
    mobile_pattern = re.compile(r'^1{1}\d{10}$')
    while receiver_mobile == '' or re.findall(mobile_pattern, receiver_mobile) == []:
        receiver_mobile = input('預留手機號碼不能為慷訓者格式不正確,請重新輸入:')
    receiver_email = input('請預留一個郵箱,方便搶到票后進行通知(例如:[email protected]):')
    while receiver_email == '':
        receiver_email = input('預留郵箱不能為空,請重新輸入:')
    # 開始搶票
    ticket = BrushTicket(user_name, password, passengers, from_time, from_station, to_station, number, seat_type, receiver_mobile, receiver_email)
    ticket.start_brush()

 最后注意:不管你是為了Python就業還是興趣愛好,記住:專案開發經驗永遠是核心,如果你沒有2020最新python入門到高級實戰視頻教程,可以去小編的Python交流.裙 :七衣衣九七七巴而五(數字的諧音)轉換下可以找到了,里面很多新python教程專案,還可以跟老司機交流討教!

本文的文字及圖片來源于網路加上自己的想法,僅供學習、交流使用,不具有任何商業用途,著作權歸原作者所有,如有問題請及時聯系我們以作處理,

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/149350.html

標籤:Python

上一篇:Python學習筆記:斷言

下一篇:初學Python爬蟲要學多久?原來這么快

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Rust中的智能指標:Box<T> Rc<T> Arc<T> Cell<T> RefCell<T> Weak

    Rust中的智能指標是什么 智能指標(smart pointers)是一類資料結構,是擁有資料所有權和額外功能的指標。是指標的進一步發展 指標(pointer)是一個包含記憶體地址的變數的通用概念。這個地址參考,或 ” 指向”(points at)一些其 他資料 。參考以 & 符號為標志并借用了他們所 ......

    uj5u.com 2023-04-20 07:24:10 more
  • Java的值傳遞和參考傳遞

    值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......

    uj5u.com 2023-04-20 07:24:04 more
  • [2]SpinalHDL教程——Scala簡單入門

    第一個 Scala 程式 shell里面輸入 $ scala scala> 1 + 1 res0: Int = 2 scala> println("Hello World!") Hello World! 檔案形式 object HelloWorld { /* 這是我的第一個 Scala 程式 * 以 ......

    uj5u.com 2023-04-20 07:23:58 more
  • 理解函式指標和回呼函式

    理解 函式指標 指向函式的指標。比如: 理解函式指標的偽代碼 void (*p)(int type, char *data); // 定義一個函式指標p void func(int type, char *data); // 宣告一個函式func p = func; // 將指標p指向函式func ......

    uj5u.com 2023-04-20 07:23:52 more
  • Django筆記二十五之資料庫函式之日期函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十五之資料庫函式之日期函式 日期函式主要介紹兩個大類,Extract() 和 Trunc() Extract() 函式作用是提取日期,比如我們可以提取一個日期欄位的年份,月份,日等資料 Trunc() 的作用則是截取,比如 2022-0 ......

    uj5u.com 2023-04-20 07:23:45 more
  • 一天吃透JVM面試八股文

    什么是JVM? JVM,全稱Java Virtual Machine(Java虛擬機),是通過在實際的計算機上仿真模擬各種計算機功能來實作的。由一套位元組碼指令集、一組暫存器、一個堆疊、一個垃圾回收堆和一個存盤方法域等組成。JVM屏蔽了與作業系統平臺相關的資訊,使得Java程式只需要生成在Java虛擬機 ......

    uj5u.com 2023-04-20 07:23:31 more
  • 使用Java接入小程式訂閱訊息!

    更新完微信服務號的模板訊息之后,我又趕緊把微信小程式的訂閱訊息給實作了!之前我一直以為微信小程式也是要企業才能申請,沒想到小程式個人就能申請。 訊息推送平臺🔥推送下發【郵件】【短信】【微信服務號】【微信小程式】【企業微信】【釘釘】等訊息型別。 https://gitee.com/zhongfuch ......

    uj5u.com 2023-04-20 07:22:59 more
  • java -- 緩沖流、轉換流、序列化流

    緩沖流 緩沖流, 也叫高效流, 按照資料型別分類: 位元組緩沖流:BufferedInputStream,BufferedOutputStream 字符緩沖流:BufferedReader,BufferedWriter 緩沖流的基本原理,是在創建流物件時,會創建一個內置的默認大小的緩沖區陣列,通過緩沖 ......

    uj5u.com 2023-04-20 07:22:49 more
  • Java-SpringBoot-Range請求頭設定實作視頻分段傳輸

    老實說,人太懶了,現在基本都不喜歡寫筆記了,但是網上有關Range請求頭的文章都太水了 下面是抄的一段StackOverflow的代碼...自己大修改過的,寫的注釋挺全的,應該直接看得懂,就不解釋了 寫的不好...只是希望能給視頻網站開發的新手一點點幫助吧. 業務場景:視頻分段傳輸、視頻多段傳輸(理 ......

    uj5u.com 2023-04-20 07:22:42 more
  • Windows 10開發教程_編程入門自學教程_菜鳥教程-免費教程分享

    教程簡介 Windows 10開發入門教程 - 從簡單的步驟了解Windows 10開發,從基本到高級概念,包括簡介,UWP,第一個應用程式,商店,XAML控制元件,資料系結,XAML性能,自適應設計,自適應UI,自適應代碼,檔案管理,SQLite資料庫,應用程式到應用程式通信,應用程式本地化,應用程式 ......

    uj5u.com 2023-04-20 07:22:35 more