Last active
July 10, 2024 20:28
-
-
Save albertocavalcante/bc40a352ecd28f653d0b4df1a0723510 to your computer and use it in GitHub Desktop.
Fetch ChromeDriver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import zipfile | |
import os | |
from io import BytesIO | |
def fetch_and_extract_zip(url, extract_to='.'): | |
# Configure the proxy if needed | |
proxies = { | |
'http': 'http://your_proxy:your_proxy_port', | |
'https': 'http://your_proxy:your_proxy_port' | |
} | |
# Fetch the ZIP file | |
response = requests.get(url, proxies=proxies) | |
if response.status_code == 200: | |
# Create a BytesIO object from the response content | |
zip_file = BytesIO(response.content) | |
# Open the ZIP file | |
with zipfile.ZipFile(zip_file, 'r') as zip_ref: | |
# Extract all contents to the specified directory | |
zip_ref.extractall(extract_to) | |
print(f'Files extracted to {extract_to}') | |
else: | |
print(f'Failed to download the file. Status code: {response.status_code}') | |
# Example usage | |
url = 'https://storage.googleapis.com/chrome-for-testing-public/113.0.5672.0/linux64/chrome-linux64.zip' | |
extract_to = './extracted_files' | |
os.makedirs(extract_to, exist_ok=True) | |
fetch_and_extract_zip(url, extract_to) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def fetch_chromedriver_url(version, platform='linux64'): | |
url = 'https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json' | |
# Configure the proxy | |
proxies = { | |
'http': 'http://your_proxy:your_proxy_port', | |
'https': 'http://your_proxy:your_proxy_port' | |
} | |
response = requests.get(url, proxies=proxies) | |
if response.status_code == 200: | |
data = response.json() | |
for v in data['versions']: | |
if v['version'] == version: | |
for download in v['downloads']['chrome']: | |
if download['platform'] == platform: | |
return download['url'] | |
return None | |
# Example usage | |
version = '113.0.5672.0' | |
platform = 'linux64' | |
chromedriver_url = fetch_chromedriver_url(version, platform) | |
if chromedriver_url: | |
print(f'Chromedriver URL for version {version} on {platform}: {chromedriver_url}') | |
else: | |
print(f'No download URL found for version {version} on {platform}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment