下载地址:www.pan38.com/dow/share.p… 提取密码:2831
该模块提供订单跟踪和状态管理功能,使用SQLite本地存储 完整项目需要配置代理IP池和验证码识别模块,建议设置5-15秒随机操作间隔避免触发风控 使用多账号轮换降低单个账号风险 添加异常处理和日志记录 遵守平台规则,仅用于学习目的
import requests import threading import time from datetime import datetime
class XianYuMonitor: def init(self): self.keywords = ["显卡", "手机", "笔记本"] self.max_price = 1000 self.min_price = 300 self.refresh_interval = 5 self.cookies = [] self.headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' }
def fetch_items(self):
while True:
for keyword in self.keywords:
url = f"https://api.xianyu.com/search?q={keyword}"
try:
response = requests.get(url, headers=self.headers)
items = response.json().get('data', [])
for item in items:
if self._filter_item(item):
self._process_item(item)
except Exception as e:
print(f"Error fetching items: {e}")
time.sleep(self.refresh_interval)
def _filter_item(self, item):
price = float(item.get('price', 0))
return (price <= self.max_price and
price >= self.min_price and
"二手" not in item.get('title', ''))
def _process_item(self, item):
print(f"[{datetime.now()}] Found item: {item['title']} ¥{item['price']}")
if self._auto_buy(item):
self._send_notification(item)
def _auto_buy(self, item):
buy_url = f"https://api.xianyu.com/order/create?item_id={item['id']}"
try:
response = requests.post(buy_url, headers=self.headers)
return response.status_code == 200
except:
return False
def _send_notification(self, item):
# 钉钉/微信通知实现
pass
if name == "main": monitor = XianYuMonitor() monitor_thread = threading.Thread(target=monitor.fetch_items) monitor_thread.start()
import pyautogui import random import time
class AutoMessage: def init(self): self.messages = [ "您好,我对您的商品很感兴趣", "请问商品还在吗?可以优惠吗?", "能发顺丰到付吗?" ] self.positions = { 'search_bar': (200, 150), 'first_item': (300, 300), 'message_btn': (800, 400), 'input_box': (500, 700), 'send_btn': (900, 700) }
def send_to_seller(self, item_url):
pyautogui.hotkey('ctrl', 't')
pyautogui.typewrite(item_url)
pyautogui.press('enter')
time.sleep(3)
pyautogui.click(*self.positions['first_item'])
time.sleep(2)
pyautogui.click(*self.positions['message_btn'])
time.sleep(1)
message = random.choice(self.messages)
pyautogui.click(*self.positions['input_box'])
pyautogui.typewrite(message)
pyautogui.click(*self.positions['send_btn'])
time.sleep(random.uniform(1, 3))
def batch_send(self, keyword, count=10):
search_url = f"https://2.taobao.com/search?q={keyword}"
for _ in range(count):
self.send_to_seller(search_url)
time.sleep(random.randint(5, 15))
if name == "main": bot = AutoMessage() bot.batch_send("iPhone", 5)