您的位置:首页 > 编程语言 > Python开发

Python笔记——异常文件读写2

2020-07-15 04:45 106 查看

1、接收用户键盘输入的字符串,统计字符出现的个数。

a=input("输入:")
count=0
for i in a:
count=count+1
print(count)

2、通过正则表达式,提取html1.txt中所有的超链接中的链接地址

import  re
b=open(r"C:\Users\PC-win10-22\Desktop\html1")
c=b.read()
a=re.findall("<href:(.*)",c)
for i in a:
print(i)

3、通过正则表达式,提取html1.txt中,所有标签value的值

import re
b=open(r"C:\Users\PC-win10-22\Desktop\html1")
c=b.read()
a=re.findall("<value:(.*)",c)
for i in a:
print(i)

4、通过正则表达式,提取html1.txt中,所有标签中同时含有 name,value的值

import re
b=open(r"C:\Users\PC-win10-22\Desktop\html1")
c=b.read()
a=re.findall("<.*value.*/>|<.*name.*/>",c)
for i in a:
print(i)

5、通过正则表达式,提取html1.txt中,所有含有input的标签

import re
b=open(r"C:\Users\PC-win10-22\Desktop\html1")
c=b.read()
a=re.findall("<input:(.*)",c)
for i in a:
print(i)

6、通过正则表达式,提取html1.txt中,表单标签中所有的数据,写入一个文件中。

import re
b=open(r"C:\Users\PC-win10-22\Desktop\html1")
c=b.read()
a=re.findall("<.*/>",c)
b=open(r"C:\Users\ASUS\Desktop\output\j.txt","w")
b.write(a)
b.close()

7、通过正则表达式,提前html1.txt中,所有表单的请求方式,以及请求地址

import re
b=open(r"C:\Users\PC-win10-22\Desktop\html1")
c=b.read()
a=re.findall("method:(.*)",c)
for i in a:
print(i)
b=re.findall("action:(.*)")
for i in b:
print(i)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: