readfileurlOther.py
563 Bytes
import re
import requests
urlList = []
# 打开文件
with open('djcardrenewal/testju/urlcontentOther', 'r', encoding='utf-8') as file:
loopIndex = 1
for line in file:
print(loopIndex)
url = line.strip()
# 发起GET请求
response = requests.get(url)
code = response.status_code
if code == 404:
urlList.append(f'{url}\n')
loopIndex+=1
# 逐行读取文件内容并打印
with open('output.txt', 'w') as file2:
for baUrl in urlList:
file2.write(baUrl)