You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
807 B
26 lines
807 B
# Zxy导入日志模块
|
|
import logging
|
|
|
|
# Zxy导入 requests 模块用于发送 HTTP 请求
|
|
import requests
|
|
from django.conf import settings
|
|
|
|
# Zxy获取日志记录器
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Zxy定义爬虫通知类
|
|
class SpiderNotify():
|
|
@staticmethod
|
|
def baidu_notify(urls):
|
|
# Zxy向百度站长平台发送 URL 提交请求
|
|
try:
|
|
data = '\n'.join(urls) # Zxy将 URL 列表拼接为字符串
|
|
result = requests.post(settings.BAIDU_NOTIFY_URL, data=data) # Zxy发送 POST 请求
|
|
logger.info(result.text) # Zxy记录响应内容
|
|
except Exception as e:
|
|
logger.error(e) # Zxy记录异常信息
|
|
|
|
@staticmethod
|
|
def notify(url):
|
|
# Zxy调用百度通知方法
|
|
SpiderNotify.baidu_notify(url) |