Determine whether a webpage can be opened? Python to determine whether a web page can be python
1 #! /Usr/bin/env python 2 # coding = UTF-8 3 import requests 4 5 headers = {6 "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) appleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.20.3.100 Safari/537.36 "} 7 8 with open ('/Users/b1ancheng/Desktop/123.txt', 'R') as f: 9 for line in f: 10 line = line. strip ('\ n '). strip ('\ ufeff') 11 url = 'HTTP: // '+ line12 print (url) 13 try: 14 response = requests. get (url, headers = headers, timeout = 5 ). status_code15 print (response) 16 if response = 200:17 print ('callable') 18 else: 19 print (response) 20 response t Exception as e: 21 with open ('/Users/b1ancheng/Desktop/1.txt', 'a + ') as f1: 22 error = f1.write (line +' \ n') 23 print (e)
Determine whether the http website is opened in batches. If the website is https, run it again.