Python從臨時郵箱獲取驗證碼的操作代碼
Python如何從臨時郵箱獲取驗證碼
安裝好依賴庫之后代碼可直接運行, captcha = re.search(r'您的驗證碼為: \*(\w+)\*', response.json()['body']['html']) 正則表達式部分改成自己的。
import random
import requests
import re
from faker import Faker
domain = "https://api.mail.cx/api/v1" # 臨時郵箱api
def generate_name():
fake = Faker('en_US')
while True:
name = fake.name().replace(' ', '_')
if len(name) <= 10:
print(f"用戶名: {name}")
return name
def getAuth():
url = domain + "/auth/authorize_token"
headers = {
'accept': 'application/json',
'Authorization': 'Bearer undefined',
}
response = requests.post(url, headers=headers)
return str(response.json())
def getMailAddress():
root_mail = ["nqmo.com", "end.tw", "uuf.me", "yzm.de"]
return generate_name() + '@' + random.choice(root_mail)
def getMailId(address, auth):
url = domain + f"/mailbox/{address}"
headers = {
'accept': 'application/json',
'Authorization': f'Bearer {auth}',
}
response = requests.get(url, headers=headers)
body = response.json()
return body[0]['id'] if len(body) and len(body[0]['id']) > 0 else None
def getCaptcha():
# 獲取token
auth = getAuth()
print(f"token: {auth}")
# 獲取郵箱地址
address = getMailAddress()
print(f"郵箱地址: {address}")
# 等待獲取驗證碼郵件
id_ = None
while id_ is None:
id_ = getMailId(address, auth)
# 獲取驗證碼
url = domain + f'/mailbox/{address}/{id_}'
headers = {
'accept': 'application/json',
'Authorization': f'Bearer {auth}',
}
response = requests.get(url, headers=headers)
# 正則匹配驗證碼,此處正則表達式匹配驗證碼改成自己的
captcha = re.search(r'您的驗證碼為: \*(\w+)\*', response.json()['body']['html'])
if captcha:
print("驗證碼:", captcha.group(1))
else:
print("找不到驗證碼")
return captcha.group(1)
if __name__ == '__main__':
getCaptcha()python 獲取郵箱驗證碼
所需要的庫自己安裝,郵箱參數(shù)自己寫。默認獲取的是6位驗證碼
from imbox import Imbox
import time
from datetime import datetime
import re
with Imbox('outlook.office365.com',
username='郵箱',
password='密碼',
ssl=True,
ssl_context=None,
starttls=False) as imbox:
all_inbox_messages = imbox.messages(unread=True)
#all_inbox_messages = imbox.messages()
code = []
for uid, message in all_inbox_messages:
msg = message.body['plain'][0].encode('utf-8')
s = re.findall(r"code: \d{6}", str(msg))##有可能多個6位數(shù)字,這里根據(jù)需要改成自己的正則表達式
code.append(str(re.findall(r"\d{6}", str(s))[0]))
print(code[len(code) - 1])到此這篇關(guān)于Python如何從臨時郵箱獲取驗證碼的文章就介紹到這了,更多相關(guān)Python獲取驗證碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python descriptor(描述符)的實現(xiàn)
這篇文章主要介紹了Python descriptor(描述符)的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
關(guān)于torch.scatter與torch_scatter庫的使用整理
這篇文章主要介紹了關(guān)于torch.scatter與torch_scatter庫的使用整理,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-09-09
用python實現(xiàn)各種數(shù)據(jù)結(jié)構(gòu)
這篇文章主要分享的是用python實現(xiàn)各種數(shù)據(jù)結(jié)構(gòu),快速排序、選擇排序、插入排序、歸并排序、堆排序heapq模塊等相關(guān)資料,感興趣的小伙伴可以參考一下2021-12-12
selenium框架中driver.close()和driver.quit()關(guān)閉瀏覽器
這篇文章主要介紹了selenium框架中driver.close()和driver.quit()關(guān)閉瀏覽器,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12
Ubuntu 14.04+Django 1.7.1+Nginx+uwsgi部署教程
django+uwsgi的部署實在是太蛋疼了.網(wǎng)上已有的教程似乎有新版本的兼容問題。最后跑到uwsgi官網(wǎng)上找的教程終于跑通了.. 不過官網(wǎng)的教程似乎有引導(dǎo)教學(xué)性質(zhì),部署的時候就顯得很繞彎路,在這里記錄下來精簡內(nèi)容2014-11-11
Python3中函數(shù)參數(shù)傳遞方式實例詳解
這篇文章主要介紹了Python3中函數(shù)參數(shù)傳遞方式,結(jié)合實例形式較為詳細的分析了Python3中函數(shù)參數(shù)傳遞的常見操作技巧,需要的朋友可以參考下2019-05-05
Python簡單調(diào)用MySQL存儲過程并獲得返回值的方法
這篇文章主要介紹了Python調(diào)用MySQL存儲過程并獲得返回值的方法,涉及Python操作MySQL存儲過程的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07

