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

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)

猜你喜欢

转载自blog.csdn.net/liaoqingjian/article/details/106899623