Selenium实现每天白嫖“巨硬”1r的自动化脚本
引言
随着Edge迎来推广期,微软推出了Microsoft Rewards来做引流手段(以下简称MR)。在MR中,用户根据选择的地区可以兑换各种奖励,包括公益事业,抽奖,虚拟物品,礼品卡等。目前汇率大约18000积分 = 100面值礼品卡,其中每天大约能获得180积分,也就是1元左右。获取积分的方式有每天使用Bing搜索、签到、完成任务等。其中Bing搜索占据了每日积分的大头(如图150积分)
从图中不难计算出,想要每天获得足够的积分,需要使用电脑搜索至少33次,手机搜索23次,实在是麻烦至极。作为一名自动化测试工程师,我认为实现自动化搜索方式是十分有必要的,于是有了这篇文章。
鸣谢
在您继续浏览之前,不妨点击一下Microsoft Rewards的推广链接助力作者赚取一点点积分吧!!
欢迎使用 Microsoft Rewards
⬆️⬆️⬆️⬆️邀请链接,点一下吧求求你了!!🥺
(可以通过链接快速注册开通Microsoft Rewards哦!!)
准备工作
在开始之前,你需要准备以下工具和环境:
- Python 3.x:确保已安装Python(作者使用的是3.11)。
- Selenium4:用于浏览器自动化(该脚本使用selenium=4.34.0,3.x版本会导致代码兼容性bug,可能不适用于本文脚本)。
- WebDriver:由于是微软的项目,仅能使用Edge浏览器。
- 代码编辑器:如VSCode或PyCharm。
- 目标平台账号:微软账号,并已登录到浏览器。
安装依赖
- 安装Python:从python.org下载并安装。
- 安装Selenium:
pip install selenium
- 下载WebDriver:
- 进入浏览器设置 -> 关于Microsoft Edge -> 记录当前版本号
- 下载链接Microsoft Edge WebDriver | Microsoft Edge Developer
- 解压msedgedriver.exe到脚本根目录位置
脚本代码
⚠️注意:运行脚本时可能需要焦点始终保持在浏览器中,并在搜索前登录弹出的浏览器窗口⚠️
PC端自动化代码,运行33次,总共获取90积分
from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom webdriver_manager.microsoft import EdgeChromiumDriverManagerfrom selenium.webdriver.edge.service import Serviceimport timeimport random# 关键词列表(100个,风格偏日常搜索场景)keywords = [ # 购物相关 \"Best laptops 2025\", \"Smartphone deals\", \"Fashion trends women\", \"Online shopping discounts\", \"Gaming console prices\", \"Home appliance reviews\", \"Sneaker brands\", \"Luxury watches\", \"Budget headphones\", \"Furniture sales\", \"Electronics deals\", \"Black Friday 2025\", \"Amazon best sellers\", \"Tech gadgets 2025\", \"Winter clothing trends\", \"Jewelry gift ideas\", # 旅游与生活 \"Top travel destinations\", \"Cheap flights 2025\", \"Hotel booking tips\", \"Beach vacation ideas\", \"City break Europe\", \"Adventure travel packages\", \"Cruise deals 2025\", \"Travel insurance comparison\", \"Camping gear reviews\", \"Best hiking trails\", \"Family vacation spots\", \"Solo travel tips\", \"Backpacking destinations\", \"Luxury resorts Asia\", \"Travel safety tips\", \"Road trip ideas\", # 新闻与时事 \"Breaking news today\", \"World news updates\", \"US election 2025\", \"Global economy trends\", \"Climate change solutions\", \"Political debates 2025\", \"International conflicts\", \"Tech industry updates\", \"Stock market predictions\", \"Health policy news\", \"Space mission updates\", \"Energy crisis 2025\", # 学术与教育 \"Online courses free\", \"Best coding bootcamps\", \"Study abroad programs\", \"Scholarship opportunities\", \"Academic research tools\", \"Math learning apps\", \"History documentaries\", \"Science podcasts\", \"University rankings 2025\", \"Career training programs\", \"Language learning tips\", \"STEM resources\", # 健康与健身 \"Weight loss diets\", \"Home workout routines\", \"Mental health tips\", \"Meditation apps\", \"Healthy meal plans\", \"Fitness equipment reviews\", \"Yoga for beginners\", \"Nutrition supplements\", \"Running shoes reviews\", \"Stress management techniques\", \"Sleep improvement tips\", \"Vegan recipes easy\", # 娱乐与文化 \"New movie releases\", \"TV show reviews 2025\", \"Music festivals 2025\", \"Book recommendations\", \"Streaming service deals\", \"Celebrity news today\", \"Top video games 2025\", \"Art exhibitions\", \"Theater shows 2025\", \"Pop music charts\", \"Comedy specials Netflix\", \"Cultural events near me\", # 科技与创新 \"Smart home devices 2025\", \"Wearable tech reviews\", \"Electric car prices\", \"AI innovations\", \"5G network updates\", \"Virtual reality headsets\", \"Drone technology\", \"Cybersecurity tips\", \"Tech startups 2025\", \"Cloud storage comparison\", \"Programming tutorials\", \"Data privacy laws\", # 其他日常搜索 \"Local weather forecast\", \"Event planning ideas\", \"DIY craft projects\", \"Pet adoption near me\", \"Gardening for beginners\", \"Car maintenance tips\", \"Home renovation ideas\", \"Wedding planning guide\", \"Photography gear reviews\", \"Best coffee machines\", \"Restaurant reviews near me\", \"Online grocery delivery\", \"Real estate trends 2025\", \"Job search websites\", \"Personal finance apps\", \"Charity organizations\"]# 设置 Edge 浏览器选项(电脑端,无移动端模拟)options = webdriver.EdgeOptions()# 如果需要无界面运行,取消注释以下行# options.add_argument(\"--headless\")options.add_argument(\"--disable-gpu\")options.add_argument(\"--no-sandbox\")options.add_argument(\"--disable-dev-shm-usage\")# 自动下载并使用 Edge WebDriverdriver_path = \"msedgedriver.exe\"service = Service(driver_path)driver = webdriver.Edge(service=service, options=options)def simulate_human_scroll(): \"\"\"模拟人类的滚动行为\"\"\" try: # 获取页面高度 page_height = driver.execute_script(\"return document.body.scrollHeight\") # 随机滚动次数(1-4次,电脑端页面较长) scroll_times = random.randint(1, 4) current_position = 0 for _ in range(scroll_times): # 随机滚动距离(100-500像素,适合电脑端页面) scroll_distance = random.randint(100, 500) # 30% 概率向上滚动 if random.random() < 0.3: scroll_distance = -scroll_distance # 确保不超出页面范围 if 0 <= current_position + scroll_distance < page_height: driver.execute_script(f\"window.scrollBy(0, {scroll_distance});\") current_position += scroll_distance else: # 滚动到顶部或底部 driver.execute_script(\"window.scrollTo(0, arguments[0]);\", 0 if current_position + scroll_distance < 0 else page_height) break # 模拟人类阅读的随机停顿(0.5-2秒) time.sleep(random.uniform(0.5, 2)) except Exception as e: print(f\"滚动时发生错误: {e}\")def bing_search(query): try: driver.get(\"https://www.bing.com\") search_box = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, \"sb_form_q\")) ) search_box.clear() search_box.send_keys(query) search_box.send_keys(Keys.RETURN) # 等待搜索结果加载 WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.CSS_SELECTOR, \"h2 a\")) ) # 模拟滚动行为 simulate_human_scroll() # 额外延迟,模拟浏览时间 time.sleep(random.uniform(2, 6)) except Exception as e: print(f\"搜索 {query} 时发生错误: {e}\")def main(): try: # 打开 Bing 登录页面(如果需要手动登录,取消注释以下代码) # driver.get(\"https://login.live.com\") # print(\"请手动登录 Microsoft 账户,然后按 Enter 继续...\") # input() # 执行33次电脑端搜索 for i in range(33): keyword = random.choice(keywords) print(f\"执行第 {i + 1} 次电脑端搜索: {keyword}\") bing_search(keyword) print(\"已完成33次电脑端搜索!\") except Exception as e: print(f\"发生错误: {e}\") finally: driver.quit()if __name__ == \"__main__\": main()
移动端自动化代码,运行23次,总共获取60积分
from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom webdriver_manager.microsoft import EdgeChromiumDriverManagerfrom selenium.webdriver.edge.service import Serviceimport timeimport random# 关键词列表(100个)keywords = [ \"Python programming\", \"AI technology\", \"Machine learning\", \"Data science\", \"Web development\", \"Cloud computing\", \"Cybersecurity\", \"Blockchain\", \"Quantum computing\", \"Big data\", \"Artificial intelligence\", \"Deep learning\", \"Software engineering\", \"DevOps\", \"Mobile apps\", \"Game development\", \"Network security\", \"Database management\", \"API integration\", \"Microservices\", \"Computer vision\", \"Natural language processing\", \"Robotics\", \"IoT devices\", \"5G technology\", \"Augmented reality\", \"Virtual reality\", \"Edge computing\", \"Serverless architecture\", \"Fintech\", \"Cryptocurrency\", \"Digital transformation\", \"Agile methodology\", \"Selenium automation\", \"Bing rewards\", \"Cloud security\", \"Web3\", \"Data analytics\", \"Neural networks\", \"Kubernetes\", \"Docker containers\", \"Cybersecurity trends\", \"Generative AI\", \"Low-code platforms\", \"Quantum cryptography\", \"Latest movies 2025\", \"Music streaming services\", \"Top Netflix shows\", \"Hollywood news\", \"Video game releases\", \"Pop culture trends\", \"Celebrity interviews\", \"Anime recommendations\", \"Streaming platforms comparison\", \"Oscar predictions 2025\", \"K-pop trends\", \"Virtual concerts\", \"Football highlights\", \"Basketball NBA news\", \"Olympics 2024 updates\", \"Tennis rankings\", \"Soccer World Cup\", \"Sports betting trends\", \"Fitness training tips\", \"Marathon training\", \"Healthy recipes\", \"Sustainable living\", \"Minimalist lifestyle\", \"Travel destinations 2025\", \"Home decor ideas\", \"Personal finance tips\", \"Mental health awareness\", \"Yoga benefits\", \"Vegan diet plans\", \"DIY home projects\", \"Eco-friendly products\", \"Budget travel tips\", \"Global news today\", \"Climate change updates\", \"Economic trends 2025\", \"International politics\", \"Tech industry news\", \"Stock market analysis\", \"World health organization updates\", \"Renewable energy trends\", \"Geopolitical events\", \"Space exploration news\", \"Online learning platforms\", \"Free coding tutorials\", \"Language learning apps\", \"STEM education trends\", \"Virtual classrooms\", \"Best universities 2025\", \"Weather forecast\", \"Local events near me\", \"Photography tips\", \"Pet care advice\", \"Gardening tips\", \"Electric vehicles 2025\", \"Smart home devices\", \"Fashion trends 2025\", \"Food delivery apps\", \"Virtual reality gaming\", \"Productivity tools\", \"Remote work tips\", \"Cryptocurrency prices\", \"Artificial intelligence ethics\", \"Space tourism\", \"Fitness trackers\"]# 设置 Edge 浏览器选项,模拟移动设备options = webdriver.EdgeOptions()mobile_user_agent = ( \"Mozilla/5.0 (Linux; Android 14; Pixel 6 Build/AP2A.240605.024) \" \"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Mobile Safari/537.36 Edge/121.0.2277.138\")options.add_argument(f\"user-agent={mobile_user_agent}\")# 如果需要无界面运行,取消注释以下行# options.add_argument(\"--headless\")options.add_argument(\"--disable-gpu\")options.add_argument(\"--no-sandbox\")options.add_argument(\"--disable-dev-shm-usage\")options.add_experimental_option(\"mobileEmulation\", { \"deviceMetrics\": {\"width\": 360, \"height\": 640, \"pixelRatio\": 3.0}, \"userAgent\": mobile_user_agent})# 自动下载并使用 Edge WebDriverdriver_path = \"msedgedriver.exe\"service = Service(driver_path)driver = webdriver.Edge(service=service, options=options)def simulate_human_scroll(): \"\"\"模拟人类的滚动行为\"\"\" try: # 获取页面高度 page_height = driver.execute_script(\"return document.body.scrollHeight\") # 随机滚动次数(1-3次) scroll_times = random.randint(1, 3) current_position = 0 for _ in range(scroll_times): # 随机滚动距离(50-300像素,适合移动端页面) scroll_distance = random.randint(50, 300) # 确保不超出页面高度 if current_position + scroll_distance < page_height: driver.execute_script(f\"window.scrollBy(0, {scroll_distance});\") current_position += scroll_distance else: # 如果接近页面底部,滚动到末尾 driver.execute_script(\"window.scrollTo(0, document.body.scrollHeight);\") break # 模拟人类阅读的随机停顿(0.5-2秒) time.sleep(random.uniform(0.5, 2)) except Exception as e: print(f\"滚动时发生错误: {e}\")def bing_search(query): try: driver.get(\"https://www.bing.com\") search_box = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, \"sb_form_q\")) ) search_box.clear() search_box.send_keys(query) search_box.send_keys(Keys.RETURN) # 等待搜索结果加载 WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.CSS_SELECTOR, \"h2 a\")) ) # 模拟滚动行为 simulate_human_scroll() # 额外延迟,模拟浏览时间 time.sleep(random.uniform(2, 6)) except Exception as e: print(f\"搜索 {query} 时发生错误: {e}\")def main(): try: # 打开 Bing 登录页面(如果需要手动登录,取消注释以下代码) # driver.get(\"https://login.live.com\") # print(\"请手动登录 Microsoft 账户,然后按 Enter 继续...\") # input() # 执行23次移动端搜索 for i in range(23): keyword = random.choice(keywords) print(f\"执行第 {i + 1} 次移动端搜索: {keyword}\") bing_search(keyword) print(\"已完成23次移动端搜索!\") except Exception as e: print(f\"发生错误: {e}\") finally: driver.quit()if __name__ == \"__main__\": main()
使用说明
分别创建不同的Python文件并运行即可,注意配置浏览器驱动放置的位置。
注意事项
- 遵守平台规则:许多平台禁止自动化脚本,违规可能导致账号封禁。请确保你的操作符合服务条款。
- 安全性:不要将账号密码硬编码在脚本中,建议使用环境变量或配置文件存储敏感信息。
- 调试:初次运行可能因页面加载时间或元素定位错误失败,可通过
time.sleep
或WebDriverWait
优化。。
免责声明
本教程仅供学习和参考目的。使用自动化脚本可能违反某些平台的服务条款,请确保遵守相关法律法规及平台规则。作者不对因使用本脚本导致的任何后果(包括但不限于账号封禁或法律责任)承担责任。请谨慎使用,并自行承担风险。
友情链接
AI工具:ChatGOAT