欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python3 ip:port格式转化成http、https格式文件

程序员文章站 2022-03-02 10:29:54
...

新手学习python第一个程序:

此脚本可以将ip:port格式的ip.txt文件转化成http\https格式的url.txt文件

如:

ip.txt:

1.1.1.1:80

1.1.1.1:8080

转化后:

url.txt

http://1.1.1.1:80

https://1.1.1.1:8080

http://1.1.1.1:80

https://1.1.1.1:8080

脚本如下:

#ip.txt中ip:port格式转换成http、https格式,保存到url.txt中
with open("ip.txt","r") as f:
    line = f.readlines()

with open("url.txt","w") as f2:
    for i in line:
        f2.write('http://'+i)

with open("url.txt","a+") as f3:
    f3.write('\n')

with open("url.txt","a+") as f4:
    for i in line:
        f4.write('https://'+i)

 

相关标签: python python