码迷,mamicode.com
首页 > 编程语言 > 详细

判断网页能否打开?python

时间:2017-10-15 17:58:28      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:webkit   htm   cep   mac os x   exce   safari   code   lin   mac os   

#!/usr/bin/env python
# coding=utf-8
import requests

headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"}

with open(‘/Users/fin4nc/Desktop/123.txt‘, ‘r‘) as f:
for line in f:
line = line.strip(‘\n‘).strip(‘\ufeff‘)
url = ‘http://‘ + line
print(url)
try:
response= requests.get(url, headers=headers, timeout=5).status_code
print(response)
if response== 200:
print(‘可打开‘)
else:
print(response)
except Exception as e:
with open(‘/Users/fin4nc/Desktop/1.txt‘, ‘a+‘) as f1:
error = f1.write(line+‘\n‘)
print(e)

判断网页能否打开?python

标签:webkit   htm   cep   mac os x   exce   safari   code   lin   mac os   

原文地址:http://www.cnblogs.com/b1ancheng/p/7671181.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!