问题遇到的现象和发生背景 python使用selenium时程序卡死,既不报错也没有继续运行,ctrl+c也无法中断,代码中略去了使用PIL在图片上作图的部分,请问是电脑问题还是代码设计问题。 - from selenium import webdriver
- import time
- from PIL import Image
- from PIL import ImageDraw
- import datetime
- import requests
- import numpy as np
-
- def scprt():
- chrome_driver = 'd:/radar_prt/chromedriver.exe'
- options = webdriver.ChromeOptions()
- options.add_argument('--headless')
- options.add_argument('window-size=1920x1080')
- driver = webdriver.Chrome(executable_path = chrome_driver, options = options)
- driver.maximize_window()
- driver.get('https://smart.zj121.com/radarNew/index.html')
- driver.execute_script("map.setView({lat:28.6,lng:120.092}, 8.4)")
- time.sleep(2)
- driver.get_screenshot_as_file("d:/radar_prt/radar_or.png")
- driver.quit()
-
- scprt()
- print('开始运行....')
- requests.adapters.DEFAULT_RETRIES = 5 # 增加重连次数
- s = requests.session()
- s.keep_alive = False # 关闭多余连接
- r = s.get('https://www.zj121.com/list/oss/res?key=zjqxfwzx-data/other/radar_HREF/&_=1642157916696').text
- rx = r.split(',', 200)
- first_rx = rx[199]
- while True:
- try :
- requests.adapters.DEFAULT_RETRIES = 5 # 增加重连次数
- s = requests.session()
- s.keep_alive = False # 关闭多余连接
- except BaseException:
- time.sleep(10)
- else:
- r = s.get('https://www.zj121.com/list/oss/res?key=zjqxfwzx-data/other/radar_HREF/&_=1642157916696').text
- rx = r.split(',', 200)
- daily_rx = rx[199]
- nt = datetime.datetime.now().strftime('%H:%M:%S')
- print(nt + ' 监测雷达更新中....')
- if first_rx != daily_rx:
- first_rx = daily_rx
- scprt()
- print(nt + ' 雷达已经更新....')
- time.sleep(np.random.randint(32, 52))
-
-
复制代码
|