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.
87 lines
3.3 KiB
87 lines
3.3 KiB
#!/usr/bin/env python3
|
|
"""
|
|
直接使用requests和BeautifulSoup查询快递 - 不依赖浏览器自动化
|
|
"""
|
|
|
|
import requests
|
|
import re
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
def check_jd_express(tracking_number):
|
|
"""
|
|
尝试多种方法查询京东快递
|
|
"""
|
|
print(f"🔍 查询京东快递: {tracking_number}")
|
|
print("=" * 60)
|
|
|
|
# 方法1: 尝试访问京东移动端查询页面
|
|
print("\n📱 方法1: 尝试京东移动端查询...")
|
|
try:
|
|
mobile_url = f"https://m.jd.com/logistics/{tracking_number}"
|
|
headers = {
|
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15',
|
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
}
|
|
response = requests.get(mobile_url, headers=headers, timeout=10, allow_redirects=True)
|
|
print(f" 状态码: {response.status_code}")
|
|
if response.status_code == 200:
|
|
print(f" 页面长度: {len(response.content)} 字节")
|
|
if "物流" in response.text or "快递" in response.text:
|
|
print(" ✅ 找到物流相关内容!")
|
|
# 简单提取一些信息
|
|
if "暂无" in response.text:
|
|
print(" ⚠️ 暂无物流信息")
|
|
elif "签收" in response.text:
|
|
print(" ✅ 已签收!")
|
|
elif "运输中" in response.text:
|
|
print(" 🚚 运输中...")
|
|
except Exception as e:
|
|
print(f" ❌ 失败: {e}")
|
|
|
|
# 方法2: 尝试快递100的移动版
|
|
print("\n🌐 方法2: 尝试快递100查询...")
|
|
try:
|
|
kuaidi100_url = f"https://m.kuaidi100.com/result.jsp?nu={tracking_number}"
|
|
headers = {
|
|
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; SM-G981B) AppleWebKit/537.36',
|
|
}
|
|
response = requests.get(kuaidi100_url, headers=headers, timeout=10, allow_redirects=True)
|
|
print(f" 状态码: {response.status_code}")
|
|
if response.status_code == 200:
|
|
print(f" 页面长度: {len(response.content)} 字节")
|
|
except Exception as e:
|
|
print(f" ❌ 失败: {e}")
|
|
|
|
# 方法3: 直接给出查询建议
|
|
print("\n" + "=" * 60)
|
|
print("\n💡 查询建议(按准确性排序):")
|
|
print("\n🥇 1. 京东APP(最推荐)")
|
|
print(" - 打开京东APP")
|
|
print(" - 我的 -> 待收货/快递查询")
|
|
print(" - 或扫描快递单二维码")
|
|
|
|
print("\n🥈 2. 京东官网")
|
|
print(" - 访问: https://www.jd.com")
|
|
print(f" - 搜索: {tracking_number}")
|
|
|
|
print("\n🥉 3. 第三方平台")
|
|
print(" - 快递100: https://www.kuaidi100.com")
|
|
print(" - 菜鸟裹裹: https://www.cainiao.com")
|
|
print(" - 支付宝/微信 -> 快递查询")
|
|
|
|
print("\n📞 京东物流客服: 950616")
|
|
print(f"\n⏰ 查询时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
print("=" * 60)
|
|
|
|
def main():
|
|
tracking_number = sys.argv[1] if len(sys.argv) > 1 else "JDX049504693863"
|
|
|
|
if tracking_number.startswith('JDX') or tracking_number.startswith('JD'):
|
|
check_jd_express(tracking_number)
|
|
else:
|
|
print(f"📦 快递单号: {tracking_number}")
|
|
print("💡 请使用官方APP或第三方平台查询")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|