python - 如何将屏幕与 Python 中的屏幕截图进行比较
问题描述
我正在制作一个 Python 程序,它可以打开Target并购买用户输入的商品。如果该项目不可用,则程序不执行任何操作并在控制台中打印一条消息。要检查该项目是否可用,我需要检查屏幕是否包含类似于我截取的屏幕截图的内容。屏幕截图如下所示。
谁能帮我这个?
解决方案
好吧,您当然可以比较两个屏幕截图,使用 matplotlib、PIL 或 opencv(甚至 numpy)等库,但我想最简单的方法是使用selenium(如果您自动导航)或 beautifulsoup4/scrapy。
就像是 :
from selenium import webdriver
browser = webdriver.Firefox()
url = "https://www.target.com/"
browser.get(url)
# navigate to find your product
out_of_stock_text = "put your stuff here"
if out_of_stock_text in browsers.page_source:
# Do your stuff here
祝你好运 !
推荐阅读
- python - pikepdf - 如何从 django 视图返回内存中的 pdf 对象
- log4j - log4j2如何选择会话而不是日期
- java - 在 Java Servlet 中集成 Google Sheets API
- android - 运行 Gradle 任务 'assembleDebug'... 参数格式不正确 -
- reactjs - 自定义 Adobe 的 React Spectrum 主题
- firebase - 构建以连接到 Firebase 时,任务“:app:processDebugResources”的 Flutter Build 失败
- python - 使用 pyinstaller 导出 tkinter python 应用程序时出错?
- javascript - 是的,有条件地使用带有无线电输入的 `when`
- sql - 如何确定它在Oracle中的索引名称索引的列/列名称
- php - Woocommerce 产品标题显示 HTML?