forked from hcjohn463/JableTVDownload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getchromedriver.py
54 lines (44 loc) · 1.61 KB
/
getchromedriver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import requests
from bs4 import BeautifulSoup
import zipfile
import shutil
import os
def get_chromedriver_version():
url = 'https://googlechromelabs.github.io/chrome-for-testing/'
response = requests.get(url)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
formatted_html = soup.prettify()
# print(formatted_html)
tr_tags = soup.find_all('tr', class_='status-ok')
for tr in tr_tags:
if tr.find('a', string="Stable"):
version_code = tr.find('code').text.strip()
print(version_code)
break
return version_code
else:
print("Fail, Code:", response.status_code)
def download_chromedriver(download_link):
url = download_link
response = requests.get(url)
if response.status_code == 200:
with open('chromedriver.zip', 'wb') as file:
file.write(response.content)
print("success!")
else:
print("Fail, Code:", response.status_code)
def unzip_chromedriver():
with zipfile.ZipFile('chromedriver.zip', 'r') as zip_ref:
zip_ref.extractall('./')
chromedriver_version = get_chromedriver_version()
download_link = f"https://storage.googleapis.com/chrome-for-testing-public/{chromedriver_version}/win64/chromedriver-win64.zip"
download_chromedriver(download_link)
unzip_chromedriver()
# move chromedriver to the root directory
file_source = "chromedriver-win64/chromedriver.exe"
file_destination = "./"
shutil.move(file_source, file_destination)
# clean up
shutil.rmtree('chromedriver-win64')
os.remove("chromedriver.zip")