2、使用在线工具
SEMrush Link Audit:提供详细的链接分析报告,包括死链、可索引性和外部链接质量。
Ahrefs Site Audit:全面的网站审计工具,可以检测死链、内部链接问题和其他SEO相关的指标。
Majestic SEO Tools:提供链接分析和排名跟踪功能,可以帮助检测死链。
W3Techs Link Checker:简单的在线工具,可以检测单个URL或整个网站的死链。
def check_links(url):
response = requests.get(url)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
for link in soup.find_all('a'):
href = link.get('href')
if href and not href.startswith(''):
try:
status = requests.head(href).status_code
print(f{href} {status})
except requests.exceptions.RequestException as e:
print(f{href} Error: {e})