re.match
re.search
re.findall
re.sub
.lstrip
.rstrip
.strip
>>> import re
>>> b = '10010000001010000'
>>> r = re.search('1(.*?)1', b)
>>> print(r.group())
1001
>>> str = ' 2 3 45 '
>>> print(str)
2 3 45
>>> print(str.lstrip()) # 删除左边的空格
2 3 45
>>> print(str.rstrip()) # 删除右边的空格
2 3 45
dict.update
dict.get
>>> dic = {'name': '李白',}
>>> print(dic['name'])
李白
>>> print(dic.get("name"))
李白
>>> print(dic['stu'])
Traceback (most recent call last):
File "" , line 1, in <module>
KeyError: 'stu'
>>> print(dic.get('stu'))
None
>>> print(dic.get('stu', 'myr'))
myr
.* 贪婪匹配
.*? 最小匹配
# re.search .*
>>> import re
>>> b = '10010000001010000'
>>> r = re.search('1(.*)1', b)
>>> print(r)
<re.Match object; span=(0, 13), match='1001000000101'>
>>> print(r.group())
1001000000101
# re.search .*?
>>> import re
>>> b = '10010000001010000'
>>> r = re.search('1(.*?)1', b)
>>> print(r.group())
>>> 1001
selenium八大定位方式
find_element(By.ID,“id”)
find_element(By.CLASS_NAME,“classname”)
find_element(By.CSS,“#id”)
find_element(By.XPATH,“//div[@name=‘csdn’]”)
find_element(By.LINK_TEXT,“text”)
find_element(By.PARTIAL_LINK,“partialtext”)
find_element(By.NAME,“name”)
find_element(By.TAG_NAME,“input”)
get_attribute(‘class’, xxxx)
.join
>>> print(a)
abcde
>>> print(a.join(['1', '3']))
1abcde3
>>> print(a.join('13'))
1abcde3
cmd ping ip, true false
subprocess.run()
(1)生成.exe文件
windows powershell中执行 pyinstaller -F -w clean_log.py
-F: 只生成一个.exe文件
-w:执行时不弹窗
clean_log.py为带转为.exe的python文件
(2)创建定时任务
cmd下执行taskschd.msc——任务计划程序库——创建基本任务——设置自动运行时间
(3)执行
1)每天自动运行
2)双击.exe文件手动运行