2
分享
比賽

這是測試活動發佈!這是測試活動發佈!這是測試活動發佈!

這是測試活動發佈!這是測試活動發佈!這是測試活動發佈!這是測試活動發佈!這是測試活動發佈!這是測試活

僑港伍氏宗親會伍時暢紀念學校主辦方
訂閲學校

活動信息

活動時間:2026-06-19 00:00 至 2026-06-30 00:00
對象:全體學生
名額:共100名額 剩餘96名額
聯繫人:測試
聯繫人號碼:13800000001/13900000002
電子郵件:123456@qq.com、147258369@qq.com
地址:學校廣場

報名方式

搵教育平台報名
聯繫學校報名:123456789@qq.com
點擊報名鏈接報名:www.baidu.com
我要報名
- 報名截止

活動內容

def update_last_updated_date():

   """更新所有记录的 last_updated_date 为当前日期"""

   with get_db_connection() as conn:

       cur = conn.cursor()

       cur.execute("UPDATE goodschool_activity_cn SET last_updated_date = CURDATE()")

       logger.info(f"✅ 更新了 {cur.rowcount} 条记录的 last_updated_date")


def main():

   logger.info("🚀 GoodSchool 活动爬虫启动(新增event-content字段提取)")

   init_database()

   

   # 添加字段(如果表已存在)

   add_last_updated_date_column()


   existing_urls = get_existing_urls()

   logger.info(f"📦 数据库中已有 {len(existing_urls)} 条记录")


   with get_driver() as driver:

       all_links = extract_all_detail_links(driver)


   new_links = [url for url in all_links if url not in existing_urls]

   logger.info(f"🆕 新增待爬取链接: {len(new_links)} 条")


   if not new_links:

       logger.info("没有新数据,程序退出")

       # 即使没有新数据,也更新 last_updated_date

       update_last_updated_date()

       return


   results = []

   with ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:

       future_to_url = {executor.submit(process_detail_page, url, existing_urls): url for url in new_links}

       completed = 0

       for future in as_completed(future_to_url):

           url = future_to_url[future]

           completed += 1

           try:

               data = future.result()

               if data:

                   results.append(data)

           except Exception as e:

               logger.error(f"❌ 处理失败 {url}: {e}")

           if completed % 10 == 0:

               logger.info(f"📈 进度: {completed}/{len(new_links)}")


   for i in range(0, len(results), BATCH_SIZE):

       batch = results[i:i + BATCH_SIZE]

       batch_save_activities(batch)

   

   # 爬取完成后,更新所有记录的 last_updated_date

   update_last_updated_date()


   logger.info(f"🎉 爬取完成,成功新增 {len(results)} 条活动数据")

logo一站式教育助力,伴學成長

Copyright © 2015-2025 搵教育.AII Rights Reserved. 本網站課程版權由搵教育平台享有,未經本公司允許不得轉載

請勿建立鏡像或通過其他違法用途使用。