Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support loading browsers.json from zip archive #278

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cloudscraper/user_agent/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import json
import os
import pathlib
import random
import re
import sys
import ssl

from collections import OrderedDict
from importlib import resources


# ------------------------------------------------------------------------------- #

Expand Down Expand Up @@ -71,7 +73,12 @@ def loadUserAgent(self, *args, **kwargs):
sys.tracebacklimit = 0
raise RuntimeError("Sorry you can't have mobile and desktop disabled at the same time.")

with open(os.path.join(os.path.dirname(__file__), 'browsers.json'), 'r') as fp:
if sys.version_info >= (3, 7):
browsers_json = resources.files(__name__) / "browsers.json"
else:
browsers_json = pathlib.Path(__file__).parent / "browsers.json"

with browsers_json.open("r") as fp:
user_agents = json.load(
fp,
object_pairs_hook=OrderedDict
Expand Down