Update README
This commit is contained in:
144
deploy_scripts/indexnow_submit.py
Normal file
144
deploy_scripts/indexnow_submit.py
Normal file
@ -0,0 +1,144 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
IndexNow 批量提交 + Google Sitemap Ping
|
||||
用法: python indexnow_submit.py
|
||||
"""
|
||||
|
||||
import urllib.request
|
||||
import urllib.parse
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import json
|
||||
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
|
||||
SITE = 'https://blog.quant-view.xyz'
|
||||
INDEXNOW_KEY = os.environ.get('INDEXNOW_KEY', 'f8a7c3e2b1d0495a8f6c7e3d2b1a0495f') # 优先从环境变量读取
|
||||
|
||||
PAGES = [
|
||||
'/',
|
||||
'/gfil-boss-panel-v70-review.html',
|
||||
'/gold-xauusd-trading-2026.html',
|
||||
'/tradingview-vs-gfil-boss.html',
|
||||
'/why-retail-traders-lose-money.html',
|
||||
'/trading-activity-tracked.html',
|
||||
'/forex-scalping-2026.html',
|
||||
'/institutional-traders-see-market-moves.html',
|
||||
'/ai-driven-market-intelligence.html',
|
||||
'/wti-crude-oil-2026.html',
|
||||
'/gfil-boss-panel-faq.html',
|
||||
'/order-flow-trading.html',
|
||||
'/bloomberg-alternative.html',
|
||||
'/websocket-vs-rest-api.html',
|
||||
'/trading-signal-tracking.html',
|
||||
'/anonymous-trading-platform.html',
|
||||
'/about.html',
|
||||
'/free-ebook.html',
|
||||
'/zh/',
|
||||
'/es/',
|
||||
'/ar/',
|
||||
]
|
||||
|
||||
# 多语言页面
|
||||
for lang in ['zh', 'es', 'ar']:
|
||||
for page in PAGES[1:17]: # 15 articles
|
||||
if page != '/' and not page.startswith('/about'):
|
||||
PAGES.append(f'/{lang}{page}')
|
||||
|
||||
HEADERS = {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
'User-Agent': 'GFIL-Blog-IndexNow/1.0',
|
||||
}
|
||||
|
||||
|
||||
def submit_indexnow():
|
||||
"""提交到 IndexNow (Bing + Yandex + Seznam)"""
|
||||
urls = [f'{SITE}{p}' for p in PAGES]
|
||||
payload = json.dumps({
|
||||
'host': 'blog.quant-view.xyz',
|
||||
'key': INDEXNOW_KEY,
|
||||
'keyLocation': f'{SITE}/{INDEXNOW_KEY}.txt',
|
||||
'urlList': urls,
|
||||
})
|
||||
|
||||
endpoints = [
|
||||
('Bing/IndexNow', 'https://api.indexnow.org/indexnow'),
|
||||
('Bing', 'https://www.bing.com/indexnow'),
|
||||
('Yandex', 'https://yandex.com/indexnow'),
|
||||
]
|
||||
|
||||
for name, endpoint in endpoints:
|
||||
try:
|
||||
req = urllib.request.Request(endpoint, data=payload.encode(), headers=HEADERS)
|
||||
with urllib.request.urlopen(req, timeout=15) as resp:
|
||||
body = resp.read().decode()
|
||||
print(f' ✅ {name}: HTTP {resp.status}')
|
||||
except Exception as e:
|
||||
print(f' ❌ {name}: {e}')
|
||||
|
||||
|
||||
def ping_google():
|
||||
"""通过 sitemap ping 通知 Google"""
|
||||
sitemap_url = f'{SITE}/sitemap.xml'
|
||||
ping_url = f'https://www.google.com/ping?sitemap={urllib.parse.quote(sitemap_url)}'
|
||||
|
||||
try:
|
||||
req = urllib.request.Request(ping_url, headers={'User-Agent': 'GFIL-Blog'})
|
||||
with urllib.request.urlopen(req, timeout=15) as resp:
|
||||
print(f' ✅ Google Sitemap Ping: HTTP {resp.status}')
|
||||
except Exception as e:
|
||||
print(f' ❌ Google Ping: {e}')
|
||||
|
||||
# Also submit news sitemap
|
||||
news_sitemap = f'{SITE}/news-sitemap.xml'
|
||||
ping2 = f'https://www.google.com/ping?sitemap={urllib.parse.quote(news_sitemap)}'
|
||||
try:
|
||||
req = urllib.request.Request(ping2, headers={'User-Agent': 'GFIL-Blog'})
|
||||
with urllib.request.urlopen(req, timeout=15) as resp:
|
||||
print(f' ✅ Google News Sitemap Ping: HTTP {resp.status}')
|
||||
except Exception as e:
|
||||
print(f' ❌ Google News Ping: {e}')
|
||||
|
||||
|
||||
def check_index_status():
|
||||
"""快速检查各页面 HTTP 状态"""
|
||||
print(f'\n--- SEO 健康检查 ---')
|
||||
issues = 0
|
||||
for page in PAGES[:20]: # 只检查核心页面
|
||||
url = f'{SITE}{page}'
|
||||
try:
|
||||
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
|
||||
with urllib.request.urlopen(req, timeout=10) as resp:
|
||||
html = resp.read().decode('utf-8', errors='replace')
|
||||
has_title = '<title>' in html
|
||||
has_desc = 'meta name="description"' in html
|
||||
if resp.status == 200 and has_title and has_desc:
|
||||
print(f' ✅ {page}')
|
||||
else:
|
||||
issues += 1
|
||||
print(f' ⚠️ {page}: HTTP {resp.status}, title={has_title}, desc={has_desc}')
|
||||
except Exception as e:
|
||||
issues += 1
|
||||
print(f' ❌ {page}: {e}')
|
||||
|
||||
if issues:
|
||||
print(f'\n ⚠️ {issues} 个页面需要关注')
|
||||
else:
|
||||
print(f'\n ✅ 所有核心页面正常')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'=== IndexNow 批量提交 ===')
|
||||
print(f'站点: {SITE}')
|
||||
print(f'URL 数量: {len(PAGES)}')
|
||||
|
||||
print(f'\n--- 提交 IndexNow ---')
|
||||
submit_indexnow()
|
||||
|
||||
print(f'\n--- 通知 Google ---')
|
||||
ping_google()
|
||||
|
||||
check_index_status()
|
||||
print(f'\n=== 完成 ===')
|
||||
Reference in New Issue
Block a user