对不起,如果这是副本,我已经寻找了大约一个小时的答案,但似乎没有找到任何答案。无论如何,我有一个充满urls的文本文件,我想检查每个urls,看看它是否存在。我需要一些帮助来理解错误消息,如果有任何方法可以修复它或不同的方法,我可以使用。
这是我的代码
import requests
filepath = 'url.txt'
with open(filepath) as fp:
url = fp.readline()
count = 1
while count != 677: #Runs through each line of my txt file
print(url)
request = requests.get(url) #Here is where im getting the error
if request.status_code == 200:
print('Web site exists')
else:
print('Web site does not exist')
url = url.strip()
count += 1
这是输出
http://www.pastaia.co
Traceback (most recent call last):
File "python", line 9, in <module>
requests.exceptions.ConnectionError:
HTTPConnectionPool(host='www.pastaia.co%0a', port=80): Max retries exceeded
with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection
object at 0x7fca82769e10>: Failed to establish a new connection: [Errno -2]
Name or service not known',))
https://stackoverflow.com/questions/51639585
复制相似问题