xinhua_base

This commit is contained in:
2025-08-11 13:10:23 +08:00
parent b43443551f
commit 4e5e35b4fa
20 changed files with 427 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
from django.core.management.base import BaseCommand
from core.models import Website
from core.utils import crawl_xinhua_article
class Command(BaseCommand):
help = '爬取新华网文章示例'
def handle(self, *args, **options):
# 假设你事先在后台建了“新华网”这个Website实例
website_name = "新华网"
try:
website = Website.objects.get(name=website_name)
except Website.DoesNotExist:
self.stdout.write(self.style.ERROR(f"网站 '{website_name}' 不存在,请先后台创建"))
return
# 这里写你想爬取的文章URL列表可以循环多篇
urls = [
"https://www.news.cn/legal/20250721/f340f7be3d5b4b938cbd6b9889b6fbdc/c.html",
]
for url in urls:
crawl_xinhua_article(url, website)