Python CookBook
platform
import platform
# 获取操作系统的位数
print('architecture: ', platform.architecture()) # architecture: ('64bit', 'ELF')
# 计算机类型/CPU架构
print('machine: ', platform.machine()) # machine: x86_64 aarch64
print('system:', platform.system()) # Linux
# 获取Linux内核版本
print('platform: ', platform.platform()) # Linux-5.4.0-42-generic-x86_64-with-glibc2.29
print('version: ', platform.version()) # #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020
# 计算机的网络名称
print('node: ', platform.node()) # idea570
# 计算机处理器信息
print('processor', platform.processor()) # processor x86_64
print('uname: ', platform.uname()) # uname_result(system='Linux', node='idea570', release='5.4.0-42-generic', version='#46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020', machine='x86_64', processor='x86_64')
print(platform.python_build()) # ('default', 'Jul 16 2020 14:00:26')
print(platform.python_compiler()) # GCC 9.3.0
print(platform.python_branch())
# python 解释器实现
print(platform.python_implementation()) # CPython
print(platform.python_revision())
print(platform.python_version_tuple()) # ('3', '8', '2')lsb_release
import lsb_release
lsb_info = lsb_release.get_distro_information()
print(lsb_info) # {'ID': 'Ubuntu', 'DESCRIPTION': 'Ubuntu 20.04.1 LTS', 'RELEASE': '20.04', 'CODENAME': 'focal'}
print('ID: ', lsb_info.get('ID')) # ID: Ubuntu
print('RELEASE: ', lsb_info.get('RELEASE')) # RELEASE: 20.04
print('DESCRIPTION: ', lsb_info.get('DESCRIPTION')) # DESCRIPTION: 'Ubuntu 20.04.1 LTS
print('CODENAME: ', lsb_info.get('CODENAME')) # CODENAME: focal密码哈希
from passlib.apps import custom_app_context as pwd_context
password = pwd_context.encrypt('password')
print(password, len(password))
# $6$rounds=656000$Q.AXo68BhIXq7LnM$bldegF6rHZ5Gi7ujPnXHOAdnAvC8srNImdIFQ9DcBWx7aF0sCWn/HryRIbyh6nuyhD3Trp.y2Sb6yVEyHsWCS1 120
result = pwd_context.verify('password', password)
print(result) # Trueselenium 登陆测试
import time
from selenium import webdriver
browser = webdriver.Firefox(executable_path='/opt/geckodriver')
browser.get('http://127.0.0.1:8080')
name_input = browser.find_element_by_xpath("//*[@type='text']") # 找到用户名的框框
pass_input = browser.find_element_by_xpath("//*[@type='password']") # 找到输入密码的框框
login_button = browser.find_element_by_class_name('loginButton') # 找到登录按钮
name_input.clear()
name_input.send_keys('admin') # 填写用户名
time.sleep(0.2)
pass_input.clear()
pass_input.send_keys('password') # 填写密码
time.sleep(0.2)
login_button.click() # 点击登录
c = browser.context()
print(c)删除字典值为空的元素
dict(filter(lambda x: x[1] != ‘’, dic.items()))




