how do I make the section described unable to test repeated links? I tried to do it by comparison, I couldn't, the script was very slow.
import re
from bs4 import BeautifulSoup
import requests
import urllib.request
r = requests.get( 'http://www.google.com' )
html = r.text
soup = BeautifulSoup( html , 'lxml' )
links = soup.find_all( 'a' , attrs={'href' : re.compile( r'^https?://' )} )
for i in links :
href = i['href']
# Test Section
req = requests.get( href )
resp = req.status_code
if resp is None or resp in [400 , 404 , 403 , 408 , 409 , 501 , 502 , 503] :
print( resp + '=' + resp.reason + '===>' + href )
with open( 'Document_ERROR.txt' , 'a' ) as arq :
arq.write( href )
arq.write( '\n' )
arq.write( resp.reason )
arq.close( )
else :
print( 'Response is {} ===> `{}'.format( resp , href ) )
with open( 'Document_OK.txt' , 'a' ) as arq :
arq.write( href )
arq.write( '\n' )
arq.close( )