47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
#!/usr/bin/env python
|
|
import os
|
|
import sys
|
|
import django
|
|
import re
|
|
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blogsite.settings')
|
|
django.setup()
|
|
|
|
from blog.models import Post
|
|
|
|
OLD_DOMAINS = ['an.xiaoan.xyz', 'xiaoan.xyz']
|
|
|
|
print("=" * 60)
|
|
print("排查残留的图片 URL")
|
|
print("=" * 60)
|
|
|
|
for domain in OLD_DOMAINS:
|
|
print(f"\n--- 搜索域名: {domain} ---\n")
|
|
|
|
# 正文里残留的
|
|
posts = Post.objects.filter(content__contains=domain)
|
|
for post in posts:
|
|
# 用正则把所有包含该域名的 src/href/url 提取出来
|
|
matches = re.findall(r'https?://' + re.escape(domain) + r'[^"\')\s]+', post.content)
|
|
if matches:
|
|
print(f" 文章: {post.title}")
|
|
for m in set(matches): # set 去重
|
|
print(f" {m}")
|
|
print()
|
|
|
|
# 摘要里残留的
|
|
posts = Post.objects.filter(excerpt__contains=domain)
|
|
for post in posts:
|
|
if not post.excerpt:
|
|
continue
|
|
matches = re.findall(r'https?://' + re.escape(domain) + r'[^"\')\s]+', post.excerpt)
|
|
if matches:
|
|
print(f" 摘要: {post.title}")
|
|
for m in set(matches):
|
|
print(f" {m}")
|
|
print()
|
|
|
|
print("=" * 60)
|
|
print("排查完成")
|