不会写代码,只能去google搜的代码
这是一段检测1.txt 文件的URL链接 并写入200状态的链接。
- #!/bin/python3
- #coding=utf-8
- import sys
- import requests
- def getHttpStatusCode(url):
- try:
- request = requests.get(url)
- httpStatusCode = request.status_code
- return httpStatusCode
- except requests.exceptions.HTTPError as e:
- return (e)
-
- if __name__ == "__main__":
- with open(‘1.txt’, ‘r’) as f:
- for line in f:
- try:
- status = getHttpStatusCode(line.strip(‘n’))#换行符
- if status == 200:
- with open(‘200.txt’,’a’) as f:
- f.write(line)
- print (line)
- else:
- print (‘no 200 code’)
- except Exception as e:
- print (e)
复制代码
这是一段去重的代码
- list = []
- for i in open("1.txt"):
- if i in list:
- continue
- list.append(i)
- with open("2.txt", ‘w’) as f:
- f.writelines(list)
复制代码
把不能把第二段的去重代码,加到第一段里面啊? 有没有python大佬?
另外有没有基础的学python教程啊,网上Python 基础教程也看了,单个都语句看得懂,从头写,完全不知从何出手啊。 网上下的代码只能看个大概,想自己学着写。 |