Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,6 +13,7 @@ import threading
|
|
| 13 |
import urllib3
|
| 14 |
import time
|
| 15 |
import base64
|
|
|
|
| 16 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
| 17 |
from selenium import webdriver
|
| 18 |
from selenium.webdriver.chrome.options import Options
|
|
@@ -38,9 +39,11 @@ def random_headers(referer):
|
|
| 38 |
"Accept": "image/webp,image/apng,image/*,*/*;q=0.8",
|
| 39 |
}
|
| 40 |
|
| 41 |
-
def
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
|
| 45 |
import requests, cloudscraper
|
| 46 |
from urllib.parse import quote, urlparse
|
|
@@ -65,9 +68,10 @@ def download_image(url, out_path, fail_log, code, suf):
|
|
| 65 |
from webdriver_manager.chrome import ChromeDriverManager
|
| 66 |
|
| 67 |
def log(msg):
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
| 71 |
|
| 72 |
USER_AGENTS = [
|
| 73 |
"Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
|
@@ -98,7 +102,7 @@ def download_image(url, out_path, fail_log, code, suf):
|
|
| 98 |
return True
|
| 99 |
log(f"Cloudscraper non-image: {r.headers.get('Content-Type')}")
|
| 100 |
except Exception as e:
|
| 101 |
-
log(f"Cloudscraper error: {e}")
|
| 102 |
|
| 103 |
# 2) requests
|
| 104 |
try:
|
|
|
|
| 13 |
import urllib3
|
| 14 |
import time
|
| 15 |
import base64
|
| 16 |
+
import traceback
|
| 17 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
| 18 |
from selenium import webdriver
|
| 19 |
from selenium.webdriver.chrome.options import Options
|
|
|
|
| 39 |
"Accept": "image/webp,image/apng,image/*,*/*;q=0.8",
|
| 40 |
}
|
| 41 |
|
| 42 |
+
def log(msg):
|
| 43 |
+
entry = f"{code}{suf}: {msg}"
|
| 44 |
+
print(entry) # See logs in console/output
|
| 45 |
+
with open(fail_log, "a") as f:
|
| 46 |
+
f.write(entry + "\n")
|
| 47 |
|
| 48 |
import requests, cloudscraper
|
| 49 |
from urllib.parse import quote, urlparse
|
|
|
|
| 68 |
from webdriver_manager.chrome import ChromeDriverManager
|
| 69 |
|
| 70 |
def log(msg):
|
| 71 |
+
entry = f"{code}{suf}: {msg}"
|
| 72 |
+
print(entry) # See logs in console/output
|
| 73 |
+
with open(fail_log, "a") as f:
|
| 74 |
+
f.write(entry + "\n")
|
| 75 |
|
| 76 |
USER_AGENTS = [
|
| 77 |
"Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
|
|
|
| 102 |
return True
|
| 103 |
log(f"Cloudscraper non-image: {r.headers.get('Content-Type')}")
|
| 104 |
except Exception as e:
|
| 105 |
+
log(f"Cloudscraper error: {e}\n{traceback.format_exc()}")
|
| 106 |
|
| 107 |
# 2) requests
|
| 108 |
try:
|