48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""
|
||
|
|
测试网站信息抓取功能
|
||
|
|
"""
|
||
|
|
import sys
|
||
|
|
if sys.platform.startswith('win'):
|
||
|
|
import io
|
||
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||
|
|
|
||
|
|
from utils.website_fetcher import WebsiteFetcher
|
||
|
|
|
||
|
|
def test_fetch():
|
||
|
|
"""测试抓取百度网站信息"""
|
||
|
|
print("="*50)
|
||
|
|
print("测试网站信息抓取功能")
|
||
|
|
print("="*50)
|
||
|
|
|
||
|
|
# 创建抓取器
|
||
|
|
fetcher = WebsiteFetcher(timeout=15)
|
||
|
|
|
||
|
|
# 测试抓取百度
|
||
|
|
test_url = "https://www.baidu.com"
|
||
|
|
print(f"\n正在抓取: {test_url}")
|
||
|
|
|
||
|
|
info = fetcher.fetch_website_info(test_url)
|
||
|
|
|
||
|
|
if info:
|
||
|
|
print("\n抓取成功!")
|
||
|
|
print("-"*50)
|
||
|
|
print(f"网站名称: {info.get('name', '')}")
|
||
|
|
print(f"网站描述: {info.get('description', '')}")
|
||
|
|
print(f"Logo URL: {info.get('logo_url', '')}")
|
||
|
|
print("-"*50)
|
||
|
|
|
||
|
|
# 测试下载Logo
|
||
|
|
if info.get('logo_url'):
|
||
|
|
print(f"\n正在下载Logo...")
|
||
|
|
logo_path = fetcher.download_logo(info['logo_url'])
|
||
|
|
if logo_path:
|
||
|
|
print(f"Logo下载成功: {logo_path}")
|
||
|
|
else:
|
||
|
|
print("Logo下载失败")
|
||
|
|
else:
|
||
|
|
print("\n抓取失败!")
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
test_fetch()
|