sub :子

process:进程

用法:

import subprocess
while True:
cmd_str = inport('请输入终端命令:')
obj = subprocrss.Popen(
cmd_str, shell = True,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE
)
success = obj.stdout.read().decode('gbk')
if success:
print(success, '正确结果')
error = obj.stderr.read().decode('gbk')
if error:
print(error, '错误结果')

re 模块

用法:

"""
^ : 代表'开头'
$ : 代表'结束'
| : 代表'或'
{} : 需要获取的值,用于限定数量
[] : 分组限制取值范围
import re
while True:
phone_number = input('请输入手机号码:').strip()
if re.match('^(13|14|15|19)[0-9]{9}$', phone_number):
print('合法')
else:
print('不合法')
字符组:
-[0-9] 可以匹配到一个0-9的字符
-[9-0] 报错,必须从小到大
-[a-z] 从小写的a-z
-[A-Z] 从大写 A-Z
-[z-A] 错误,只能从小到大,根据ASCII 表来匹配大小
-[A-z] 从大写到A写到小写z 注意:顺序必须要按照ASCII码数值的顺序编写 import re
res = re.match('[A-Z a-z 0-9]{8}', 'Tank9527')
print(res)
print(res.group()) re模块中三种比较重要方法:
- findall(): ---> []
可以匹配所有的字符,拿到一个返回值,返回结果是一个列表 - search (): ---->obj ---> obj.group()
在匹配一个字符成功后,拿到结果后结束,不往后匹配 - match() ---> obj ---> obj.group()
从匹配字符的开头匹配,若开头不是想要的内容,则返回None import re
str = 'sean tank json'
res = re.findall('[z-a]{4}', str)
print(res) import re
str = 'sean tamk json'
res =re.search('[z-a]{4}', str)
print(res.group()) import re
str = 'sean tank json'
res = re.match('[z-a]{4}', str)
print(res.group())
"""

爬虫爬取信息:

爬虫四部原则:

1、发送请求    request

2、获取响应数据:对方机器直接返回的

3、解析并提取想要的数据: re

4、保存提取后的数据:with open()

爬虫三部曲:

1、发送请求

2、解析数据

3、保存数据

#1、发送请求
def get_page(url):
response = requests.get(url) return response
#2、解析数据
def parser_page(text):
#re.findall('正则表达式', '过滤的文本')
res_list = re.findall(
)
for movie_tuple in res_list:
#print(movie_tuple)
yield movie_tuple #3、保存数据
def save_date(res_list_)
with open('xx')

subprocess 模块 与 re 模块的更多相关文章

  1. Python第十一天 异常处理 glob模块和shlex模块 打开外部程序和subprocess模块 subprocess类 Pipe管道 operator模块 sorted函数 os模块 hashlib模块 platform模块 csv模块

    Python第十一天    异常处理  glob模块和shlex模块    打开外部程序和subprocess模块  subprocess类  Pipe管道  operator模块   sorted函 ...

  2. python常用模块-调用系统命令模块(subprocess)

    python常用模块-调用系统命令模块(subprocess) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. subproces基本上就是为了取代os.system和os.spaw ...

  3. python基础语法13 内置模块 subprocess,re模块,logging日志记录模块,防止导入模块时自动执行测试功能,包的理论

    subprocess模块: - 可以通过python代码给操作系统终端发送命令, 并且可以返回结果. sub: 子    process: 进程 import subprocess while Tru ...

  4. [xml模块、hashlib模块、subprocess模块、os与sys模块、configparser模块]

    [xml模块.hashlib模块.subprocess模块.os与sys模块.configparser模块] xml模块 XML:全称 可扩展标记语言,为了能够在不同的平台间继续数据的交换,使交换的数 ...

  5. PEP 324 subprocess 新的进程模块 -- Python官方文档译文 [原创]

    PEP 324 -- subprocess 新的进程模块(subprocess - New process module) 英文原文:https://www.python.org/dev/peps/p ...

  6. random模块、os模块、序列化模块、sy模块s、subprocess模块

    random随机数模块 random.random( ) 随机产生一个0-1之间的小数 print(random.random()) # 0.31595547439342897 random.rand ...

  7. python-Day5-深入正则表达式--冒泡排序-时间复杂度 --常用模块学习:自定义模块--random模块:随机验证码--time & datetime模块

    正则表达式   语法:             mport re #导入模块名 p = re.compile("^[0-9]") #生成要匹配的正则对象 , ^代表从开头匹配,[0 ...

  8. python全栈开发-hashlib模块(数据加密)、suprocess模块、xml模块

    一.hashlib模块 1.什么叫hash:hash是一种算法(3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法 ...

  9. Python第十五天 datetime模块 time模块 thread模块 threading模块 Queue队列模块 multiprocessing模块 paramiko模块 fabric模块

    Python第十五天  datetime模块 time模块   thread模块  threading模块  Queue队列模块  multiprocessing模块  paramiko模块  fab ...

  10. Python爬虫与数据分析之模块:内置模块、开源模块、自定义模块

    专栏目录: Python爬虫与数据分析之python教学视频.python源码分享,python Python爬虫与数据分析之基础教程:Python的语法.字典.元组.列表 Python爬虫与数据分析 ...

随机推荐

  1. 使用定时器实现在console中打印内容

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. Hibernate4教程二:基本配置(2)

    <hibernate-mapping>元素 这个元素是xxx.hbm.xml配置的根元素,定义如下: java代码: <hibernate-mapping schema=" ...

  3. oracle ALL视图

    select  *  from  ALL_ALL_TABLES  -- 用户可存取的所有表. select  *  from  ALL_BASE_TABLE_MVIEWS -- 用户可存取的所有物化视 ...

  4. CSS 针对谷歌浏览器(Chrome) safari的webkit核心浏览器CSS hack

    @media screen and (-webkit-min-device-pixel-ratio:0) { ul#navUL ul a{padding:8px 2px;word-break:keep ...

  5. rdev - 查询/设置内核映像文件的根设备,RAM 磁盘大小或视频模式

    总览 SYNOPSIS rdev [ -rvh ] [ -o offset ] [ image [ value [ offset ] ] ] rdev [ -o offset ] [ image [ ...

  6. 几种激活Profile的方式

    方法一: 选择spring.profiles.active spring.profiles.active=prodspring.profiles.active=dev 方法二: 选择spring.pr ...

  7. css day1

    基础知识 css:层叠样式表 以html为基础,提供丰富的功能,如字体.颜色.背景的控制及整体排版 css中只有(冒号):  没有(等于号)= css样式规则 1.选择器用于指定css样式作用的htm ...

  8. 【LeetCode】字符串 string(共112题)

    [3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...

  9. PLC 控制系统资源

    之前整理的PC高级语言与PLC通讯代码下载链接:三菱:http://blog.sina.com.cn/s/blog_16d7d3ecb0102x6wj.html倍福:http://bbs.elecfa ...

  10. vue之路由传参三种基本方式

    现有如下场景,点击父组件的li元素跳转到子组件中,并携带参数,便于子组件获取数据. 父组件中: <li v-for="article in articles" @click= ...