-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIMPROVED-keepgrabbing.py
45 lines (40 loc) · 1.22 KB
/
IMPROVED-keepgrabbing.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
import subprocess
import urllib.request
import random
import sys
class NoBlocks(Exception):
pass
def getblocks():
try:
response = urllib.request.urlopen("http://{?REDACTED?}/grab")
r = response.read().decode('utf-8') # Decode bytes to string
if '<html' in r.lower():
raise NoBlocks
return r.split()
except Exception as e:
print(f"Error fetching blocks: {e}")
raise NoBlocks
if len(sys.argv) > 1:
prefix = ['--socks5', sys.argv[1]]
else:
prefix = [] # You could specify an interface here if necessary
def line(x):
return ['curl'] + prefix + [
'-H', f"Cookie: TENACIOUS={str(random.random())[3:]}",
'-o', f'pdfs/{x}.pdf',
f"http://www.jstor.org/stable/pdfplus/{x}.pdf?acceptTC=true"
]
while True:
try:
blocks = getblocks()
for block in blocks:
print(block)
# Using subprocess.run() instead of Popen().wait()
subprocess.run(line(block), check=True)
except NoBlocks:
print("No blocks available, retrying...")
except KeyboardInterrupt:
print("Interrupted by user, exiting.")
break
except Exception as e:
print(f"An error occurred: {e}")