Last active
January 17, 2021 21:37
-
-
Save yonderbread/fb71f2b01eef77de71af3767735b6e13 to your computer and use it in GitHub Desktop.
Janky optifine downloader (download without ads lol)
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
from bs4 import BeautifulSoup | |
from lxml import html as htm | |
import requests | |
html = BeautifulSoup(requests.get('https://optifine.net/downloads').content, 'html.parser') | |
entries = html.find_all('td', class_='colMirror') | |
links = [] | |
for e in entries: | |
links.append(e.a['href']) | |
if __name__ == '__main__': | |
print('Enter corresponding number for Optifine version.') | |
print('Type QUIT to exit.') | |
for i in range(0, len(links)): | |
print(f'[{str(i)}] {links[i].split("?f=")[-1].split(".jar")[0]}') | |
running = True | |
while running: | |
c = input('Selection > ') | |
if c == 'QUIT': | |
running = False | |
if not c.isdigit(): | |
print('Please enter an integer') | |
elif int(c) not in range(0, len(links)): | |
print('Not valid option') | |
ver = links[int(c)] | |
text = requests.get(ver).content | |
tree = htm.fromstring(text) | |
url = 'https://optifine.net/' + tree.xpath('//*[@id="Download"]/a')[0].attrib['href'] | |
filename = url.split('?f=')[-1].split('&x=')[0] | |
print('Downloading ' + filename) | |
with open(filename, 'wb') as f: | |
req = requests.get(url, stream=True) | |
for chunk in req.iter_content(chunk_size=1024): | |
if chunk: | |
f.write(chunk) | |
f.close() | |
print('Completed') |
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
lxml | |
beautifulsoup4 | |
requests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment