This commit is contained in:
van
2026-04-26 13:39:19 +08:00
parent fa25bfd784
commit a89703ea72
12 changed files with 2154 additions and 25 deletions

View File

@@ -13,8 +13,7 @@ from sqlalchemy.orm import sessionmaker, declarative_base
CHROME_PATH = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
# 固定商品详情页 URL
TARGET_URL = "https://detail.tmall.com/item.htm?abbucket=1&id=735141569627&ltk2=1753093866331wbixx4bjhgx78xdlrpyxq&ns=1&priceTId=213e074d17530938630755244e1109&skuId=5667837161089&spm=a21n57.1.hoverItem.2&utparam=%7B%22aplus_abtest%22%3A%228c55408acbff553514850c28e821c3b4%22%7D&xxc=taobaoSearch"
# MySQL 配置
TARGET_URL = "https://detail.tmall.com/item.htm?abbucket=1&id=629109576049&mi_id=0000ug1x7t_mV0K12gYppRSVQ7NozSDtS3YwUTM7oCeMS5w&ns=1&skuId=5800648665359&spm=a21n57.1.hoverItem.1&utparam=%7B%22aplus_abtest%22%3A%2254df76059607f4cb191afc7c675e8349%22%7D&xxc=taobaoSearch"# MySQL 配置
db_config = {
"host": "192.168.8.88",
"port": 3306,
@@ -96,7 +95,7 @@ def fetch_taobao_comments():
return []
# 开始监听指定请求
target_url = 'https://h5api.m.tmall.com/h5/mtop.taobao.rate.detaillist.get/6.0/?jsv=2.7.5'
target_url = 'https://h5api.m.tmall.com/h5/mtop.taobao.rate.detaillist.get/6.0/?jsv=2.7.4'
page.listen.start(target_url)
seen_ids = set()
@@ -157,6 +156,8 @@ def save_taobao_comments_to_db(comments):
user_nick = comment.get('userNick', '匿名用户')
pic_list = comment.get('feedPicPathList', [])
comment_date = comment.get('feedbackDate', '')
# 从评论数据中提取 skuId 作为 product_id
sku_id = comment.get('skuId', '')
exists = session.query(TaobaoComment).filter_by(comment_id=comment_id).first()
if exists:
@@ -166,7 +167,7 @@ def save_taobao_comments_to_db(comments):
picture_urls = [url for url in pic_list if url.startswith('//')]
new_comment = TaobaoComment(
product_id="735141569627",
product_id=sku_id, # 使用 skuId 替代硬编码的 product_id
user_name=user_nick,
comment_text=feedback,
comment_id=comment_id,
@@ -174,7 +175,7 @@ def save_taobao_comments_to_db(comments):
comment_date=comment_date
)
session.add(new_comment)
print(f"正在写入评论: {comment_id}")
print(f"正在写入评论: {comment_id}, skuId: {sku_id}")
session.commit()
except Exception as e:
session.rollback()