Commit e0f318f5 authored by Michael Murtaugh's avatar Michael Murtaugh

added cookie trick, now using requests

parent e5ab5c6f
Pipeline #412 canceled with stages
......@@ -10,19 +10,38 @@ from urllib.request import urlopen
import sys, json, os
from argparse import ArgumentParser
# https://stackoverflow.com/questions/49530566/download-an-image-using-selenium-webdriver-in-python?noredirect=1&lq=1
import requests
headers = {
"User-Agent":
"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"
}
BUFSIZE = 1024 * 1000
def wget (url, tofile):
f = urlopen(url)
count = 0
with open(tofile, "wb") as fout:
while True:
data = f.read(BUFSIZE)
if data == "":
break
count += len(data)
fout.write(data)
return count
print ("Downloading image {0}".format(url), file=sys.stderr)
s = requests.session()
s.headers.update(headers)
for cookie in b.get_cookies():
c = {cookie['name']: cookie['value']}
s.cookies.update(c)
r = s.get(url, allow_redirects=True)
open(tofile, 'wb').write(r.content)
return 100
# f = urlopen(url)
# count = 0
# with open(tofile, "wb") as fout:
# while True:
# data = f.read(BUFSIZE)
# if data == "":
# break
# count += len(data)
# fout.write(data)
# return count
def image_path (x):
x = x.replace(" ", "_").lower()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment