【问题标题】:python screenshot send via emailpython截图通过电子邮件发送
【发布时间】:2021-03-17 02:59:30
【问题描述】:

也许是在黑暗中拍摄,但我正在将屏幕截图脚本(使用 PIL)和 Twilio 与 SMS 拼凑在一起,以尝试捕获网页的屏幕截图并通过 SMS(或通过电子邮件作为第二个选项)发送) 到目的地,以便我可以查看该图像。到目前为止,有大量用于向目的地发送电子邮件或 SMS 消息的脚本。但是,捕获屏幕截图然后通过 SMS 发送该屏幕截图的中间步骤没有任何意义。无法使用 Twilio 或任何其他工具通过 SMS 发送图像。

import numpy as np 
import cv2 
import pyautogui 
import csv
import time
from time import sleep
from datetime import datetime
import random
import math
import os
import itertools
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import StaleElementReferenceException

options = Options()
ua = UserAgent(verify_ssl=False)
userAgent = ua.random
#print('Current UserAgent {}'.format(userAgent))
options.add_argument(f'user-agent={userAgent}')
options.add_argument("--no-sandbox")
#options.add_argument("--headless")
options.add_argument('--window-size=1920,1080') #this enables clicking things while in headless mode
#driver = webdriver.Chrome(executable_path='chromedriver', options=options)
driver.delete_all_cookies()
searchpage = '[webpage address]'
driver.get(searchpage)
time.sleep(2)

#this takes the screenshot
image = pyautogui.screenshot() 
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR) 
# writing it to the disk using opencv 
cv2.imwrite("[image name.png]", image)
time.sleep(2)
path = "[name of image]"

# Reading an image in default mode
image = cv2.imread(path)

# Window name in which image is displayed
window_name = 'image'

# closing all open windows
cv2.destroyAllWindows()

【问题讨论】:

  • 如何确定截屏时间。您是在网页上运行脚本还是在使用 Selenium Web 驱动程序(内置)
  • 是的。我有那部分工作,即使用 selenium 并访问一个页面,然后捕获屏幕截图。
  • 好的,您介意在您的问题中添加一些您目前拥有的代码吗?
  • @KalebaKBKeitshokile 我编辑了这个问题。但是,我想我已经弄清楚了。我可以获取该站点的屏幕截图,然后使用带有 python 的 smtp 方法发送该图像的电子邮件。应该解决了。
  • 这就是我的想法,如果您的解决方案有效,请将其发布在下面作为答案,以便将来人们可以参考您的问题

标签: python image sms


【解决方案1】:

粗略的解决方案:

  • 使用https://wkhtmltopdf.org/ 将网页捕获为 jpeg 或 png
  • 将 jpeg 或 png 保存到您的短信软件可以发送的位置
  • 让短信软件把jpeg/png发送到你要的手机号

有点取决于你是否有截图。网页是 html 又名不是图像。网络浏览器将其呈现到屏幕上。您需要将其转换为 jpeg/png 的软件。 PIL 进行图像处理,但不适用于 html。

【讨论】:

    猜你喜欢
    • 2011-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-04
    • 2011-09-14
    • 2022-08-18
    • 2018-09-20
    • 2015-10-26
    相关资源
    最近更新 更多