Could not close temporary folder: %s

from selenium import webdriver
import time
import smtplib
from email.header import Header
from email.mime.text import MIMEText

driver = webdriver.Chrome('C:\Python\Tools\chromedriver.exe')
#driver.fullscreen_window()
driver.get('http://www.meurthe-et-moselle.gouv.fr/booking/create/22259/1')
driver.implicitly_wait(4)
driver.find_element_by_id("planning22263").click()
#driver.find_element_by_xpath("//*[@id='condition_Booking']//input[@type='checkbox']").click()
time.sleep(5)
driver.find_element_by_xpath("//*[@name='nextButton']").click()
time.sleep(7)
#if driver.current_window_handle ("//*[@h2='Vérification de disponibilité']")driver.refresh()
#else
text = driver.find_element_by_id("inner_Booking").text
print(text)
attribute = driver.find_element_by_id("dialog_Booking").get_attribute('type')
print(attribute)
result = driver.find_element_by_id("dialog_Booking").is_displayed()
print(result)

#def send_email(text,result):    #函数中邮箱信息改为自己的
# 第三方 SMTP 服务
mail_host="smtp.gmail.com"  #设置服务器
mail_user="****[email protected]"    #用户名
mail_pass="****"   #口令 
mail_use_STARTTLS = True   #使用ssl 
 
sender = '****@hotmail.com'
receivers = ['****@gmail.com']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
 
message = MIMEText(text, 'plain', 'utf-8')
message['From'] = Header("rdv_prfecture", 'utf-8')
message['To'] =  Header("测试", 'utf-8')
 
subject = 'Python SMTP 邮件测试'
message['Subject'] = Header(subject, 'utf-8')
text = ("disponile:%s dialog:%s "%(text,result)) 
 
try:
    server = smtplib.SMTP(mail_host,587)
    server.starttls()
   # server.connect(mail_host, 587)    # 25 为 SMTP 端口号
    server.login(mail_user,mail_pass)  
    server.sendmail(sender, receivers, message.as_string())
    print ("邮件发送成功")
except smtplib.SMTPException:
    print ("Error: 无法发送邮件")
		
time.sleep(10)
#return driver
driver.quit()

Note that this is a script for the windwos environment python3, and regarding linux still to be modified, the selfium module of python automating web pages,*** requires installation of drive-driven Webdrivers, use of the Chrome browser needs to be matched with current Chrome version 83.04103.116, chrome_webdriver downloading address:

https://chromedriver.chromium.org/

Functional introduction, automatically select an appointment item and then click to get an appointment. If not disponible, send an email notification non-disponible. Add a scheduled task to the server to run once in an hour!

from selenium import webdriver
import time
import smtplib
from email.header import Header
from email.mime.text import MIMEText

driver = webdriver.Firefox()
driver.get("http://www.meurthe-et-moselle.gouv.fr");
cookie = driver.get_cookies()
time.sleep(5)
#driver.manage().deleteAllCookies();
#driver.findElement(By.xpath("//ul[@id='productListMain']/li[1]/span/a")).click();

#driver.fullscreen_window()
driver.get('http://www.meurthe-et-moselle.gouv.fr/booking/create/22259/1')

driver.implicitly_wait(4)
driver.find_element_by_id("planning22263").click()
#driver.find_element_by_xpath("//*[@id='condition_Booking']//input[@type='checkbox']").click()

time.sleep(5)

driver.find_element_by_xpath("//*[@name='nextButton']").click()
time.sleep(7)

#if driver.current_window_handle ("//*[@h2='Vérification de disponibilité']")driver.refresh()
#else

text = driver.find_element_by_id("inner_Booking").text
print(text)
attribute = driver.find_element_by_id("dialog_Booking").get_attribute('type')
print(attribute)
result = driver.find_element_by_id("dialog_Booking").is_displayed()
print(result)

#def send_email(text,result):    #函数中邮箱信息改为自己的
# 第三方 SMTP 服务
mail_host="smtp.gmail.com"  #设置服务器
mail_user="***[email protected]"    #用户名
mail_pass="***"   #口令 
mail_use_STARTTLS = True   #使用ssl 

sender = '[email protected]'
receivers = ['***@gmail.com']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
message = MIMEText(text, 'plain', 'utf-8')
message['From'] = Header("rdv_prfecture", 'utf-8')
message['To'] =  Header("测试", 'utf-8')
subject = 'Python SMTP 邮件测试'
message['Subject'] = Header(subject, 'utf-8')
text = ("disponile:%s dialog:%s "%(text,result)) 

try:
    server = smtplib.SMTP(mail_host,587)
    server.starttls()
   # server.connect(mail_host, 587)    # 25 为 SMTP 端口号
    server.login(mail_user,mail_pass)  
    server.sendmail(sender, receivers, message.as_string())
    print ("邮件发送成功")
except smtplib.SMTPException:
    print ("Error: 无法发送邮件")
time.sleep(10)
#return driver
driver.quit()

linux environmental requirements: python3, pip3, need to install pip3 install selfium, need to download Firefox ‘s webdriver drive and hang on the server using crontab for sh auto.sh

*** Prefix gmail smtp required

1.smtp port number is not default 25, smtp is 587.
2. Must have “Allow for less secure applications”
Better log this server over the gmail account again.

Cookie problem solved:*** Target site needs a manual visit before illegal operations are blacklisted as pache

未经允许不得转载:萌萌Apprentissage » Could not close temporary folder: %s

Like (0) 打赏

Comments 0

Protected with IP Blacklist CloudIP Blacklist Cloud
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

//下一个脚本特效
//下一个脚本