MonitoringOfPublicOpinion/Extension_Check.py

38 lines
1.6 KiB
Python
Raw Normal View History

2020-06-24 03:55:27 +00:00
import os
import requests
import zipfile
import getpass
import re
def check_extension():
if not os.path.exists("chromedriver.exe"):
print('正在安装插件')
r = requests.get('https://cdn.npm.taobao.org/dist/chromedriver/2.43/chromedriver_win32.zip')
with open("chromdriver.zip", "wb") as code:
code.write(r.content)
f = zipfile.ZipFile('chromdriver.zip')
f.extractall()
f.close()
os.remove('chromdriver.zip')
if os.path.exists("C:\\Users\\" + getpass.getuser() + "\\AppData\\Local\\Google\\Chrome\\Application\\"):
dirlist = os.listdir("C:\\Users\\" + getpass.getuser() + "\\AppData\\Local\\Google\\Chrome\\Application\\")
try:
version = re.search(r'\d+[.]\d+',' '.join(dirlist),re.S).group(0)
except:
version = 0
if float(version)<76.0:
print('正在安装浏览器')
r = requests.get(
'http://dl.google.com/release2/chrome/TKr3C6FyNalyEmyRiPmVhw_76.0.3809.132/76.0.3809.132_chrome_installer.exe')
with open("chrome76.exe", "wb") as code:
code.write(r.content)
os.system('chrome76.exe')
os.remove('chrome76.exe')
else:
print('正在安装浏览器')
r = requests.get(
'http://dl.google.com/release2/chrome/TKr3C6FyNalyEmyRiPmVhw_76.0.3809.132/76.0.3809.132_chrome_installer.exe')
with open("chrome76.exe", "wb") as code:
code.write(r.content)
os.system('chrome76.exe')
os.remove('chrome76.exe')
os.system('cls')